UNPKG

cdk-nextjs

Version:

Deploy Next.js apps on AWS with CDK

102 lines (101 loc) 3.66 kB
import { CustomResource } from "aws-cdk-lib"; import { IDistribution } from "aws-cdk-lib/aws-cloudfront"; import { IVpc } from "aws-cdk-lib/aws-ec2"; import { AccessPoint } from "aws-cdk-lib/aws-efs"; import { Function as LambdaFunction } from "aws-cdk-lib/aws-lambda"; import { Bucket } from "aws-cdk-lib/aws-s3"; import { Construct } from "constructs"; import { OptionalCustomResourceProps } from "./generated-structs/OptionalCustomResourceProps"; import { OptionalFunctionProps } from "./generated-structs/OptionalFunctionProps"; import { OptionalPostDeployCustomResourceProperties } from "./generated-structs/OptionalPostDeployCustomResourceProperties"; export interface NextjsPostDeployOverrides { readonly functionProps?: OptionalFunctionProps; /** * Props that define the custom resource */ readonly customResourceProps?: OptionalCustomResourceProps; /** * Properties passed into custom resource that are passed to Lambda event handler. */ readonly customResourceProperties?: OptionalPostDeployCustomResourceProperties; } export interface NextjsPostDeployProps { readonly accessPoint: AccessPoint; readonly buildId: string; /** * @see {@link NextjsBuild.buildImageDigest} */ readonly buildImageDigest: string; /** * If true, logs details in custom resource lambda * @default true */ readonly debug?: boolean; /** * CloudFront Distribution to invalidate */ readonly distribution?: IDistribution; /** * Override props for every construct. */ readonly overrides?: NextjsPostDeployOverrides; /** * @see {@link NextjsBaseProps.relativePathToPackage} */ readonly relativePathToPackage?: string; /** * Required for `NextjsType.GlobalFunctions` and `NextjsType.GlobalContainers` */ readonly staticAssetsBucket?: Bucket; readonly vpc: IVpc; } export interface PostDeployCustomResourceProperties { /** * Build ID of current deployment. Used to prune FileSystem of directories * with old build ids and prune S3 based on metadat and `msTtl` */ readonly buildId: string; /** * @see {@link NextjsBuild.buildImageDigest} */ readonly buildImageDigest: string; /** * @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/cloudfront/command/CreateInvalidationCommand/ * @default * { distributionId: this.props.distribution?.distributionId, invalidationBatch: { callerReference: new Date().toISOString(), paths: { quantity: 1, items: ["/*"], // invalidate all paths }, }, } */ readonly createInvalidationCommandInput?: Record<string, any>; /** * Time to live in milliseconds * * Must be string because of CloudFormation Custom Resource limitation * @default (1000 * 60 * 60 * 24 * 30).toString() */ readonly msTtl: string; readonly staticAssetsBucketName?: string; } /** * Performs post deployment tasks in custom resource. * * 1. CloudFront Invalidation (defaults to /*) * 2. Prunes FileSystem by removing directories that don't match this deployments BUILD_ID * 3. Prune S3 by removing objects that don't have next-build-id metadata of * current build id AND are older than `msTtl` */ export declare class NextjsPostDeploy extends Construct { customResource: CustomResource; lambdaFunction: LambdaFunction; private props; constructor(scope: Construct, id: string, props: NextjsPostDeployProps); private createFunction; private createCustomResource; }