UNPKG

open-next-cdk

Version:

Deploy a NextJS app using OpenNext packaging to serverless AWS using CDK

126 lines (125 loc) 4.1 kB
import { Duration, Size } from 'aws-cdk-lib'; import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; import { IVpc } from 'aws-cdk-lib/aws-ec2'; import * as s3 from 'aws-cdk-lib/aws-s3'; import { BucketDeployment } from 'aws-cdk-lib/aws-s3-deployment'; import { Construct } from 'constructs'; import { NextjsBaseProps } from './NextjsBase'; import { NextjsBuild } from './NextjsBuild'; import { NextjsS3EnvRewriter } from './NextjsS3EnvRewriter'; export interface NextjsAssetsCachePolicyProps { /** * Cache-control max-age default for S3 static assets. * Default: 30 days. */ readonly staticMaxAgeDefault?: Duration; /** * Cache-control stale-while-revalidate default for S3 static assets. * Default: 1 day. */ readonly staticStaleWhileRevalidateDefault?: Duration; } export interface NextjsAssetsDeploymentProps extends NextjsBaseProps { /** * The `NextjsBuild` instance representing the built Nextjs application. */ readonly nextBuild: NextjsBuild; /** * Properties for the S3 bucket containing the NextJS assets. */ readonly bucket: s3.IBucket; /** * Distribution to invalidate when assets change. */ readonly distribution?: cloudfront.IDistribution; /** * Override the default S3 cache policies created internally. */ readonly cachePolicies?: NextjsAssetsCachePolicyProps; /** * Set to true to delete old assets (defaults to false). * Recommended to only set to true if you don't need the ability to roll back deployments. */ readonly prune?: boolean; /** * In case of useEfs, vpc is required */ readonly vpc?: IVpc; /** * In case of useEfs, vpc is required */ readonly useEfs?: boolean; /** * memoryLimit for lambda function which been run by BucketDeployment */ readonly memoryLimit?: number; /** * ephemeralStorageSize for lambda function which been run by BucketDeployment */ readonly ephemeralStorageSize?: Size; } /** * Effectively a Partial<NextjsAssetsCachePolicyProps> to satisfy JSII */ export interface NextjsAssetsDeploymentPropsDefaults extends NextjsBaseProps { /** * The `NextjsBuild` instance representing the built Nextjs application. */ readonly nextBuild?: NextjsBuild; /** * Properties for the S3 bucket containing the NextJS assets. */ readonly bucket?: s3.IBucket; /** * Distribution to invalidate when assets change. */ readonly distribution?: cloudfront.IDistribution; /** * Override the default S3 cache policies created internally. */ readonly cachePolicies?: NextjsAssetsCachePolicyProps; /** * Set to true to delete old assets (defaults to false). * Recommended to only set to true if you don't need the ability to roll back deployments. */ readonly prune?: boolean; /** * In case of useEfs, vpc is required */ readonly vpc?: IVpc; /** * In case of useEfs, vpc is required */ readonly useEfs?: boolean; /** * memoryLimit for lambda function which been run by BucketDeployment */ readonly memoryLimit?: number; /** * ephemeralStorageSize for lambda function which been run by BucketDeployment */ readonly ephemeralStorageSize?: Size; } /** * Uploads NextJS-built static and public files to S3. * * Will rewrite CloudFormation references with their resolved values after uploading. */ export declare class NextJsAssetsDeployment extends Construct { /** * Bucket containing assets. */ bucket: s3.IBucket; /** * Asset deployments to S3. */ deployments: BucketDeployment[]; rewriter?: NextjsS3EnvRewriter; staticTempDir: string; protected props: NextjsAssetsDeploymentProps; constructor(scope: Construct, id: string, props: NextjsAssetsDeploymentProps); protected prepareArchiveDirectory(): string; private uploadS3Assets; private _getStaticFilesForRewrite; } export declare function listDirectory(dir: string): string[];