UNPKG

@scloud/cdk-patterns

Version:

Serverless CDK patterns for common infrastructure needs

37 lines (36 loc) 1.97 kB
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'; /** * @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 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 WebApiProps { lambda: Function; zone: IHostedZone; domainName?: string; distributionProps?: Partial<DistributionProps>; errorResponses?: ErrorResponse[]; } /** * Builds a web API, backed by a single Lambda function - a kind of "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. * Dumping requests with file expensions means the majority of spam requests will not invoke your Lambda. * Typically spam requests are probing for wordpress *.xml files, *.php files, .env files etc. */ export declare class WebApi extends Construct { lambda: Function; bucket: Bucket; distribution: Distribution; api: LambdaRestApi; certificate: DnsValidatedCertificate; constructor(scope: Construct, id: string, props: WebApiProps); }