cdk-nextjs-standalone
Version:
Deploy a NextJS app to AWS using CDK and OpenNext.
154 lines (153 loc) • 5.96 kB
TypeScript
import { Distribution } from 'aws-cdk-lib/aws-cloudfront';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import { OptionalNextjsDistributionProps, OptionalNextjsDomainProps, OptionalNextjsImageProps, OptionalNextjsInvalidationProps, OptionalNextjsRevalidationProps, OptionalNextjsServerProps, OptionalNextjsStaticAssetsProps } from './generated-structs';
import { OptionalNextjsBuildProps } from './generated-structs/OptionalNextjsBuildProps';
import { NextjsBuild } from './NextjsBuild';
import { NextjsDistribution } from './NextjsDistribution';
import { NextjsDomain, NextjsDomainProps } from './NextjsDomain';
import { NextjsImage } from './NextjsImage';
import { NextjsOverrides } from './NextjsOverrides';
import { NextjsRevalidation } from './NextjsRevalidation';
import { NextjsServer } from './NextjsServer';
import { NextjsStaticAssets } from './NextjsStaticAssets';
export interface NextjsConstructOverrides {
readonly nextjsBuildProps?: OptionalNextjsBuildProps;
readonly nextjsStaticAssetsProps?: OptionalNextjsStaticAssetsProps;
readonly nextjsServerProps?: OptionalNextjsServerProps;
readonly nextjsImageProps?: OptionalNextjsImageProps;
readonly nextjsRevalidationProps?: OptionalNextjsRevalidationProps;
readonly nextjsDomainProps?: OptionalNextjsDomainProps;
readonly nextjsDistributionProps?: OptionalNextjsDistributionProps;
readonly nextjsInvalidationProps?: OptionalNextjsInvalidationProps;
}
export interface NextjsProps {
/**
* Optional value to prefix the Next.js site under a /prefix path on CloudFront.
* Usually used when you deploy multiple Next.js sites on same domain using /sub-path
*
* Note, you'll need to set [basePath](https://nextjs.org/docs/app/api-reference/next-config-js/basePath)
* in your `next.config.ts` to this value and ensure any files in `public`
* folder have correct prefix.
* @example "/my-base-path"
*/
readonly basePath?: string;
/**
* Optional build command override value.
* @default 'npx @opennextjs/aws@^3 build'
*/
readonly buildCommand?: string;
/**
* The directory to execute `npm run build` from. By default, it is `nextjsPath`.
* Can be overridden, particularly useful for monorepos where `build` is expected to run
* at the root of the project.
*/
readonly buildPath?: string;
/**
* Optional CloudFront Distribution created outside of this construct that will
* be used to add Next.js behaviors and origins onto. Useful with `basePath`.
*/
readonly distribution?: Distribution;
/**
* Props to configure {@link NextjsDomain}. See details on how to customize at
* {@link NextjsDomainProps}
*/
readonly domainProps?: NextjsDomainProps;
/**
* Custom environment variables to pass to the NextJS build **and** runtime.
*/
readonly environment?: Record<string, string>;
/**
* Optional S3 Bucket to use, defaults to assets bucket
*/
readonly imageOptimizationBucket?: s3.IBucket;
/**
* Relative path to the directory where the NextJS project is located.
* Can be the root of your project (`.`) or a subdirectory (`packages/web`).
*/
readonly nextjsPath: string;
/**
* Override props for every construct. Enables deep customization. Use with caution as
* you can override all props. Recommend reviewing source code to see props
* you'll be overriding before using.
*/
readonly overrides?: NextjsOverrides;
/**
* Less build output.
*/
readonly quiet?: boolean;
/**
* Skips running Next.js build. Useful if you want to deploy `Nextjs` but
* haven't made any changes to Next.js app code.
* @default false
*/
readonly skipBuild?: boolean;
/**
* By default all CloudFront cache will be invalidated on deployment.
* This can be set to true to skip the full cache invalidation, which
* could be important for some users.
*/
readonly skipFullInvalidation?: boolean;
/**
* Streaming allows you to send data to the client as it's generated
* instead of waiting for the entire response to be generated.
*/
readonly streaming?: boolean;
}
/**
* The `Nextjs` construct is a higher level construct that makes it easy to create a NextJS app.
*
* Your standalone server application will be bundled using o(utput tracing and will be deployed to a Lambda function.
* Static assets will be deployed to an S3 bucket and served via CloudFront.
* You must use Next.js 10.3.0 or newer.
*
* Please provide a `nextjsPath` to the Next.js app inside your project.
*
* @example
* new Nextjs(this, "Web", {
* nextjsPath: path.resolve("packages/web"),
* })
*/
export declare class Nextjs extends Construct {
protected props: NextjsProps;
/**
* The main NextJS server handler lambda function.
*/
serverFunction: NextjsServer;
/**
* The image optimization handler lambda function.
*/
imageOptimizationFunction: NextjsImage;
/**
* Built NextJS project output.
*/
nextBuild: NextjsBuild;
/**
* Asset deployment to S3.
*/
staticAssets: NextjsStaticAssets;
/**
* Optional Route53 Hosted Zone, ACM Certificate, and Route53 DNS Records
*/
domain?: NextjsDomain;
/**
* CloudFront distribution.
*/
distribution: NextjsDistribution;
/**
* Revalidation handler and queue.
*/
revalidation: NextjsRevalidation;
lambdaFunctionUrl: lambda.FunctionUrl;
imageOptimizationLambdaFunctionUrl: lambda.FunctionUrl;
constructor(scope: Construct, id: string, props: NextjsProps);
/**
* URL of Next.js App.
*/
get url(): string;
/**
* Convenience method to access `Nextjs.staticAssets.bucket`.
*/
get bucket(): s3.IBucket;
}