@scloud/cdk-patterns
Version:
Serverless CDK patterns for common infrastructure needs
80 lines (79 loc) • 5.31 kB
TypeScript
import * as route53 from 'aws-cdk-lib/aws-route53';
import { Construct } from 'constructs';
import { Stack } from 'aws-cdk-lib';
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { BehaviorOptions, Distribution } from 'aws-cdk-lib/aws-cloudfront';
import { LambdaRestApi } from 'aws-cdk-lib/aws-apigateway';
import { Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
import { UserPool } from 'aws-cdk-lib/aws-cognito';
/**
* @deprecated Use RedirectWww instead
*/
export declare function redirectWww(construct: Construct, name: string, zone: route53.IHostedZone, certificate?: ICertificate, domain?: string): void;
/**
* @deprecated Use WebApp instead
*
* Builds a dynamic web application, backed by a Lambda function.
* @param stack The CDK stack. The name of the stack will be included in the API Gateway description to aid readability/identification in the AWS console.
* @param name The name for the web app. This will infulence naming for Cloudfront, API Gateway, Lambda and the static bucket.
* @param zone The DNS zone for this web app.
* @param environment Any environment variables your lambda will need to handle requests.
* @param domain Optional: by default the zone apex will be mapped to the Cloudfront distribution (e.g. 'example.com') but yo ucan specify a subdomain here (e.g. 'subdomain.example.com').
* @param lambdaProps Optional: if you need to modify the properties of the Lambda function, you can use this parameter.
* @param headers Optional: any headers you want passed through Cloudfront in addition to the defaults of User-Agent and Referer
* @param defaultIndex Default: true. Maps a viewer request for '/' to a request for /index.html.
* @param wwwRedirect Default: true. Redirects www requests to the bare domain name, e.g. www.example.com->example.com, www.sub.example.com->sub.example.com.
* @returns
*/
export declare function webApp(stack: Stack, name: string, zone: route53.IHostedZone, environment?: {
[key: string]: string;
}, domain?: string, lambdaProps?: Partial<FunctionProps>, headers?: string[], defaultIndex?: boolean, wwwRedirect?: boolean, autoDeleteObjects?: boolean): {
lambda: Function;
api: LambdaRestApi;
bucket: Bucket;
distribution: Distribution;
};
/**
* @deprecated Use WebRoutes instead
*
* Builds a dynamic web application, backed by Lambda functions that serve specific routes.
* By default a single Lambda is generated that responds to the / route.
* Alternatively you can pass a mapping of routes to functions
* (or map to undedfined, which means functions will be generated for you)
* @param stack The CDK stack. The name of the stack will be included in the API Gateway description to aid readability/identification in the AWS console.
* @param name The name for the web app. This will infulence naming for Cloudfront, API Gateway, Lambda and the static bucket.
* @param zone The DNS zone for this web app.
* @param routes The set of routes you would like to be handled by Lambda functions. Functions can be undefined (meaning theu will be generated for you). You can optionally request specific headers (deafult: User-Agent and Referer) to be passed through Cloudfront
* @param domain Optional: by default the zone apex will be mapped to the Cloudfront distribution (e.g. 'example.com') but yo ucan specify a subdomain here (e.g. 'subdomain.example.com').
* @param defaultIndex Default: true. Maps a viewer request for '/' to a request for /index.html.
* @param wwwRedirect Default: true. Redirects www requests to the bare domain name, e.g. www.example.com->example.com, www.sub.example.com->sub.example.com.
* @returns
*/
export declare function webAppRoutes(stack: Stack, name: string, zone: route53.IHostedZone, routes?: {
[pathPattern: string]: Function | undefined;
}, domain?: string | undefined, cognitoPool?: UserPool | undefined, defaultIndex?: boolean, wwwRedirect?: boolean, autoDeleteObjects?: boolean): {
lambdas: {
[path: string]: Function;
};
bucket: Bucket;
distribution: Distribution;
};
/**
* @deprecated Use WebFrontend instead
*
* A Cloudfront distribution backed by an s3 bucket.
* NB us-east-1 is required for Cloudfront certificates:
* https://docs.aws.amazon.com/cdk/api/v1/docs/aws-cloudfront-readme.html
* @param construct Parent CDK construct (typically 'this')
* @param zone DNS zone to use for the distribution - default the zone name will be used as the DNS name.
* @param name The domain name for the distribution (and name for associated resources)
* @param defaultBehavior By default an s3 bucket will be created, but this parameter can override that default behavior (sic.)
* @param wwwRedirect whether a www. subdomain should be created to redirect to the main domain
* @returns The distribution and (if created) static bucket
*/
export declare function cloudFront(stack: Stack, name: string, zone: route53.IHostedZone, defaultBehavior?: BehaviorOptions, domain?: string | undefined, defaultIndex?: boolean, wwwRedirect?: boolean, autoDeleteObjects?: boolean): {
bucket?: Bucket;
distribution: Distribution;
};
export declare function redirect(construct: Construct, name: string, zone: route53.IHostedZone, targetDomain: string): void;