@scloud/cdk-patterns
Version:
Serverless CDK patterns for common infrastructure needs
52 lines (51 loc) • 2.94 kB
TypeScript
import { DnsValidatedCertificate } from 'aws-cdk-lib/aws-certificatemanager';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { Distribution, DistributionProps, ErrorResponse } from 'aws-cdk-lib/aws-cloudfront';
import { LambdaRestApi } from 'aws-cdk-lib/aws-apigateway';
import { Function } from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import { IHostedZone } from 'aws-cdk-lib/aws-route53';
import { ZipFunctionProps } from './ZipFunction';
/**
* @param lambda The function which will respond to incoming request events.
* @param zone The DNS zone for this web app.
* @param domainName Optional: by default the zone name will be used (e.g. 'example.com') a different domain here (e.g. 'subdomain.example.com').
* @param defaultIndex Default: false. If true, maps a viewer request for '/' to an s3 request for /index.html.
* @param redirectWww Default: true. Redirects www requests to the bare domain name, e.g. www.example.com->example.com, www.sub.example.com->sub.example.com.
* @param distributionProps Optional: If you want to add additional properties to the Cloudfront distribution, you can pass them here.
* @param errorResponses Optional: If you want to add custom error responses to the Cloudfront distribution, you can pass them here.
*/
export interface WebAppProps {
lambda: Function;
zone: IHostedZone;
domainName?: string;
defaultIndex?: boolean;
redirectWww?: boolean;
distributionProps?: Partial<DistributionProps>;
errorResponses?: ErrorResponse[];
}
/**
* Builds a dynamic web application, backed by a single Lambda function, also knowm as a "Lambda-lith" (https://github.com/cdk-patterns/serverless/blob/main/the-lambda-trilogy/README.md)
*
* This construct sends requests that don't have a file extension to the Lambda. Static content is handled by routing requests that match *.* (eg *.js. *.css) to an S3 bucket.
*/
export declare class WebApp extends Construct {
lambda: Function;
bucket: Bucket;
distribution: Distribution;
api: LambdaRestApi;
certificate: DnsValidatedCertificate;
constructor(scope: Construct, id: string, props: WebAppProps);
/**
* Creates a WebApp backed by a Node.js Lambda function.
*
* Memory defaults to 3008 MB because this has the effest of assigning more compute resource and therefore reduces latency.
*/
static node(scope: Construct, id: string, zone: IHostedZone, domainName?: string, defaultIndex?: boolean, redirectWww?: boolean, functionProps?: ZipFunctionProps): WebApp;
/**
* Creates a WebApp backed by a Python Lambda function.
*
* Memory defaults to 3008 MB because this has the effest of assigning more compute resource and therefore reduces latency.
*/
static python(scope: Construct, id: string, zone: IHostedZone, domainName?: string, defaultIndex?: boolean, redirectWww?: boolean, functionProps?: ZipFunctionProps): WebApp;
}