The Nextjs
construct is a higher level CDK construct that makes it easy to create a NextJS app.
Your standalone server application will be bundled using output 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"),
})
import { Nextjs } from 'cdk-nextjs-standalone'
new Nextjs(scope: Construct, id: string, props: NextjsProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
NextjsProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: NextjsProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
public toString(): string
Returns a string representation of this construct.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { Nextjs } from 'cdk-nextjs-standalone'
Nextjs.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
imageCachePolicyProps |
aws-cdk-lib.aws_cloudfront.CachePolicyProps |
The default CloudFront cache policy properties for images. |
lambdaCachePolicyProps |
aws-cdk-lib.aws_cloudfront.CachePolicyProps |
The default CloudFront cache policy properties for the Lambda server handler. |
lambdaOriginRequestPolicyProps |
aws-cdk-lib.aws_cloudfront.OriginRequestPolicyProps |
The default CloudFront lambda origin request policy. |
staticCachePolicyProps |
aws-cdk-lib.aws_cloudfront.CachePolicyProps |
The default CloudFront cache policy properties for static pages. |
bucketArn |
string |
The ARN of the internally created S3 Bucket. |
bucketName |
string |
The name of the internally created S3 Bucket. |
distributionDomain |
string |
The domain name of the internally created CloudFront Distribution. |
distributionId |
string |
The ID of the internally created CloudFront Distribution. |
url |
string |
The CloudFront URL of the website. |
customDomainUrl |
string |
If the custom domain is enabled, this is the URL of the website with the custom domain. |
assetsDeployment |
NextJsAssetsDeployment |
Asset deployment to S3. |
bucket |
aws-cdk-lib.aws_s3.IBucket |
Bucket containing NextJS static assets. |
distribution |
aws-cdk-lib.aws_cloudfront.Distribution |
The internally created CDK Distribution instance. |
lambdaFunctionUrl |
aws-cdk-lib.aws_lambda.FunctionUrl |
No description. |
nextBuild |
NextjsBuild |
Built NextJS project output. |
originAccessIdentity |
aws-cdk-lib.aws_cloudfront.IOriginAccessIdentity |
No description. |
serverFunction |
NextJsLambda |
The main NextJS server handler lambda function. |
tempBuildDir |
string |
No description. |
certificate |
aws-cdk-lib.aws_certificatemanager.ICertificate |
The AWS Certificate Manager certificate for the custom domain. |
configBucket |
aws-cdk-lib.aws_s3.Bucket |
No description. |
hostedZone |
aws-cdk-lib.aws_route53.IHostedZone |
The Route 53 hosted zone for the custom domain. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly imageCachePolicyProps: CachePolicyProps;
- Type: aws-cdk-lib.aws_cloudfront.CachePolicyProps
The default CloudFront cache policy properties for images.
public readonly lambdaCachePolicyProps: CachePolicyProps;
- Type: aws-cdk-lib.aws_cloudfront.CachePolicyProps
The default CloudFront cache policy properties for the Lambda server handler.
public readonly lambdaOriginRequestPolicyProps: OriginRequestPolicyProps;
- Type: aws-cdk-lib.aws_cloudfront.OriginRequestPolicyProps
The default CloudFront lambda origin request policy.
public readonly staticCachePolicyProps: CachePolicyProps;
- Type: aws-cdk-lib.aws_cloudfront.CachePolicyProps
The default CloudFront cache policy properties for static pages.
public readonly bucketArn: string;
- Type: string
The ARN of the internally created S3 Bucket.
public readonly bucketName: string;
- Type: string
The name of the internally created S3 Bucket.
public readonly distributionDomain: string;
- Type: string
The domain name of the internally created CloudFront Distribution.
public readonly distributionId: string;
- Type: string
The ID of the internally created CloudFront Distribution.
public readonly url: string;
- Type: string
The CloudFront URL of the website.
public readonly customDomainUrl: string;
- Type: string
If the custom domain is enabled, this is the URL of the website with the custom domain.
public readonly assetsDeployment: NextJsAssetsDeployment;
- Type: NextJsAssetsDeployment
Asset deployment to S3.
public readonly bucket: IBucket;
- Type: aws-cdk-lib.aws_s3.IBucket
Bucket containing NextJS static assets.
public readonly distribution: Distribution;
- Type: aws-cdk-lib.aws_cloudfront.Distribution
The internally created CDK Distribution
instance.
public readonly lambdaFunctionUrl: FunctionUrl;
- Type: aws-cdk-lib.aws_lambda.FunctionUrl
public readonly nextBuild: NextjsBuild;
- Type: NextjsBuild
Built NextJS project output.
public readonly originAccessIdentity: IOriginAccessIdentity;
- Type: aws-cdk-lib.aws_cloudfront.IOriginAccessIdentity
public readonly serverFunction: NextJsLambda;
- Type: NextJsLambda
The main NextJS server handler lambda function.
public readonly tempBuildDir: string;
- Type: string
public readonly certificate: ICertificate;
- Type: aws-cdk-lib.aws_certificatemanager.ICertificate
The AWS Certificate Manager certificate for the custom domain.
public readonly configBucket: Bucket;
- Type: aws-cdk-lib.aws_s3.Bucket
public readonly hostedZone: IHostedZone;
- Type: aws-cdk-lib.aws_route53.IHostedZone
The Route 53 hosted zone for the custom domain.
Uploads NextJS-built static and public files to S3.
Will rewrite CloudFormation references with their resolved values after uploading.
import { NextJsAssetsDeployment } from 'cdk-nextjs-standalone'
new NextJsAssetsDeployment(scope: Construct, id: string, props: NextjsAssetsDeploymentProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
NextjsAssetsDeploymentProps |
No description. |
- Type: constructs.Construct
- Type: string
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
public toString(): string
Returns a string representation of this construct.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { NextJsAssetsDeployment } from 'cdk-nextjs-standalone'
NextJsAssetsDeployment.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
bucket |
aws-cdk-lib.aws_s3.IBucket |
Bucket containing assets. |
deployments |
aws-cdk-lib.aws_s3_deployment.BucketDeployment[] |
Asset deployments to S3. |
staticTempDir |
string |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly bucket: IBucket;
- Type: aws-cdk-lib.aws_s3.IBucket
Bucket containing assets.
public readonly deployments: BucketDeployment[];
- Type: aws-cdk-lib.aws_s3_deployment.BucketDeployment[]
Asset deployments to S3.
public readonly staticTempDir: string;
- Type: string
Represents a built NextJS application.
This construct runs npm build
in standalone output mode inside your nextjsPath
.
This construct can be used by higher level constructs or used directly.
import { NextjsBuild } from 'cdk-nextjs-standalone'
new NextjsBuild(scope: Construct, id: string, props: NextjsBuildProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
NextjsBuildProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: NextjsBuildProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
readPublicFileList |
No description. |
public toString(): string
Returns a string representation of this construct.
public readPublicFileList(): string[]
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { NextjsBuild } from 'cdk-nextjs-standalone'
NextjsBuild.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
buildPath |
string |
The path to the directory where the server build artifacts are stored. |
nextPublicDir |
string |
Public static files. |
nextStandaloneBuildDir |
string |
NextJS project inside of standalone build. |
nextStandaloneDir |
string |
Entire NextJS build output directory. |
nextStaticDir |
string |
Static files containing client-side code. |
props |
NextjsBuildProps |
No description. |
tempBuildDir |
string |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly buildPath: string;
- Type: string
The path to the directory where the server build artifacts are stored.
public readonly nextPublicDir: string;
- Type: string
Public static files.
E.g. robots.txt, favicon.ico, etc.
public readonly nextStandaloneBuildDir: string;
- Type: string
NextJS project inside of standalone build.
Contains server code and manifests.
public readonly nextStandaloneDir: string;
- Type: string
Entire NextJS build output directory.
Contains server and client code and manifests.
public readonly nextStaticDir: string;
- Type: string
Static files containing client-side code.
public readonly props: NextjsBuildProps;
- Type: NextjsBuildProps
public readonly tempBuildDir: string;
- Type: string
Build a lambda function from a NextJS application to handle server-side rendering, API routes, and image optimization.
import { NextJsLambda } from 'cdk-nextjs-standalone'
new NextJsLambda(scope: Construct, id: string, props: NextjsLambdaProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
NextjsLambdaProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: NextjsLambdaProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
public toString(): string
Returns a string representation of this construct.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { NextJsLambda } from 'cdk-nextjs-standalone'
NextJsLambda.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
lambdaFunction |
aws-cdk-lib.aws_lambda.Function |
No description. |
configBucket |
aws-cdk-lib.aws_s3.Bucket |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly lambdaFunction: Function;
- Type: aws-cdk-lib.aws_lambda.Function
public readonly configBucket: Bucket;
- Type: aws-cdk-lib.aws_s3.Bucket
Lambda layer for Next.js. Contains Sharp 0.30.0.
import { NextjsLayer } from 'cdk-nextjs-standalone'
new NextjsLayer(scope: Construct, id: string, props: NextjsLayerProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
NextjsLayerProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: NextjsLayerProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
applyRemovalPolicy |
Apply the given removal policy to this resource. |
addPermission |
Add permission for this layer version to specific entities. |
public toString(): string
Returns a string representation of this construct.
public applyRemovalPolicy(policy: RemovalPolicy): void
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
- Type: aws-cdk-lib.RemovalPolicy
public addPermission(id: string, permission: LayerVersionPermission): void
Add permission for this layer version to specific entities.
Usage within
the same account where the layer is defined is always allowed and does not
require calling this method. Note that the principal that creates the
Lambda function using the layer (for example, a CloudFormation changeset
execution role) also needs to have the lambda:GetLayerVersion
permission on the layer version.
- Type: string
- Type: aws-cdk-lib.aws_lambda.LayerVersionPermission
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
isOwnedResource |
Returns true if the construct was created by CDK, and false otherwise. |
isResource |
Check whether the given construct is a Resource. |
fromLayerVersionArn |
Imports a layer version by ARN. |
fromLayerVersionAttributes |
Imports a Layer that has been defined externally. |
import { NextjsLayer } from 'cdk-nextjs-standalone'
NextjsLayer.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
import { NextjsLayer } from 'cdk-nextjs-standalone'
NextjsLayer.isOwnedResource(construct: IConstruct)
Returns true if the construct was created by CDK, and false otherwise.
- Type: constructs.IConstruct
import { NextjsLayer } from 'cdk-nextjs-standalone'
NextjsLayer.isResource(construct: IConstruct)
Check whether the given construct is a Resource.
- Type: constructs.IConstruct
import { NextjsLayer } from 'cdk-nextjs-standalone'
NextjsLayer.fromLayerVersionArn(scope: Construct, id: string, layerVersionArn: string)
Imports a layer version by ARN.
Assumes it is compatible with all Lambda runtimes.
- Type: constructs.Construct
- Type: string
- Type: string
import { NextjsLayer } from 'cdk-nextjs-standalone'
NextjsLayer.fromLayerVersionAttributes(scope: Construct, id: string, attrs: LayerVersionAttributes)
Imports a Layer that has been defined externally.
- Type: constructs.Construct
the parent Construct that will use the imported layer.
- Type: string
the id of the imported layer in the construct tree.
- Type: aws-cdk-lib.aws_lambda.LayerVersionAttributes
the properties of the imported layer.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
env |
aws-cdk-lib.ResourceEnvironment |
The environment this resource belongs to. |
stack |
aws-cdk-lib.Stack |
The stack in which this resource is defined. |
layerVersionArn |
string |
The ARN of the Lambda Layer version that this Layer defines. |
compatibleRuntimes |
aws-cdk-lib.aws_lambda.Runtime[] |
The runtimes compatible with this Layer. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly env: ResourceEnvironment;
- Type: aws-cdk-lib.ResourceEnvironment
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
public readonly stack: Stack;
- Type: aws-cdk-lib.Stack
The stack in which this resource is defined.
public readonly layerVersionArn: string;
- Type: string
The ARN of the Lambda Layer version that this Layer defines.
public readonly compatibleRuntimes: Runtime[];
- Type: aws-cdk-lib.aws_lambda.Runtime[]
The runtimes compatible with this Layer.
import { BaseSiteDomainProps } from 'cdk-nextjs-standalone'
const baseSiteDomainProps: BaseSiteDomainProps = { ... }
Name | Type | Description |
---|---|---|
domainName |
string |
The domain to be assigned to the website URL (ie. domain.com). |
alternateNames |
string[] |
Specify additional names that should route to the Cloudfront Distribution. |
certificate |
aws-cdk-lib.aws_certificatemanager.ICertificate |
Import the certificate for the domain. |
domainAlias |
string |
An alternative domain to be assigned to the website URL. |
hostedZone |
aws-cdk-lib.aws_route53.IHostedZone |
Import the underlying Route 53 hosted zone. |
isExternalDomain |
boolean |
Set this option if the domain is not hosted on Amazon Route 53. |
public readonly domainName: string;
- Type: string
The domain to be assigned to the website URL (ie. domain.com).
Supports domains that are hosted either on Route 53 or externally.
public readonly alternateNames: string[];
- Type: string[]
Specify additional names that should route to the Cloudfront Distribution.
Note, certificates for these names will not be automatically generated so the certificate
option must be specified.
public readonly certificate: ICertificate;
- Type: aws-cdk-lib.aws_certificatemanager.ICertificate
Import the certificate for the domain.
By default, SST will create a certificate with the domain name. The certificate will be created in the us-east-1
(N. Virginia) region as required by AWS CloudFront.
Set this option if you have an existing certificate in the us-east-1
region in AWS Certificate Manager you want to use.
public readonly domainAlias: string;
- Type: string
An alternative domain to be assigned to the website URL.
Visitors to the alias will be redirected to the main domain. (ie. www.domain.com
).
Use this to create a www.
version of your domain and redirect visitors to the root domain.
public readonly hostedZone: IHostedZone;
- Type: aws-cdk-lib.aws_route53.IHostedZone
Import the underlying Route 53 hosted zone.
public readonly isExternalDomain: boolean;
- Type: boolean
Set this option if the domain is not hosted on Amazon Route 53.
import { BaseSiteEnvironmentOutputsInfo } from 'cdk-nextjs-standalone'
const baseSiteEnvironmentOutputsInfo: BaseSiteEnvironmentOutputsInfo = { ... }
Name | Type | Description |
---|---|---|
environmentOutputs |
{[ key: string ]: string} |
No description. |
path |
string |
No description. |
stack |
string |
No description. |
public readonly environmentOutputs: {[ key: string ]: string};
- Type: {[ key: string ]: string}
public readonly path: string;
- Type: string
public readonly stack: string;
- Type: string
import { BaseSiteReplaceProps } from 'cdk-nextjs-standalone'
const baseSiteReplaceProps: BaseSiteReplaceProps = { ... }
Name | Type | Description |
---|---|---|
files |
string |
No description. |
replace |
string |
No description. |
search |
string |
No description. |
public readonly files: string;
- Type: string
public readonly replace: string;
- Type: string
public readonly search: string;
- Type: string
import { CreateArchiveArgs } from 'cdk-nextjs-standalone'
const createArchiveArgs: CreateArchiveArgs = { ... }
Name | Type | Description |
---|---|---|
directory |
string |
No description. |
zipFileName |
string |
No description. |
zipOutDir |
string |
No description. |
compressionLevel |
number |
No description. |
fileGlob |
string |
No description. |
quiet |
boolean |
No description. |
public readonly directory: string;
- Type: string
public readonly zipFileName: string;
- Type: string
public readonly zipOutDir: string;
- Type: string
public readonly compressionLevel: number;
- Type: number
public readonly fileGlob: string;
- Type: string
public readonly quiet: boolean;
- Type: boolean
import { NextjsAssetsDeploymentProps } from 'cdk-nextjs-standalone'
const nextjsAssetsDeploymentProps: NextjsAssetsDeploymentProps = { ... }
Name | Type | Description |
---|---|---|
nextjsPath |
string |
Relative path to the directory where the NextJS project is located. |
compressionLevel |
number |
0 - no compression, fatest 9 - maximum compression, slowest. |
environment |
{[ key: string ]: string} |
Custom environment variables to pass to the NextJS build and runtime. |
isPlaceholder |
boolean |
Skip building app and deploy a placeholder. |
nodeEnv |
string |
Optional value for NODE_ENV during build and runtime. |
quiet |
boolean |
Less build output. |
tempBuildDir |
string |
Directory to store temporary build files in. |
nextBuild |
NextjsBuild |
The NextjsBuild instance representing the built Nextjs application. |
bucket |
aws-cdk-lib.aws_s3.IBucket | aws-cdk-lib.aws_s3.BucketProps |
Properties for the S3 bucket containing the NextJS assets. |
distribution |
aws-cdk-lib.aws_cloudfront.IDistribution |
Distribution to invalidate when assets change. |
prune |
boolean |
Set to true to delete old assets (defaults to false). |
public readonly nextjsPath: string;
- Type: string
Relative path to the directory where the NextJS project is located.
Can be the root of your project (.
) or a subdirectory (packages/web
).
public readonly compressionLevel: number;
- Type: number
- Default: 1
0 - no compression, fatest 9 - maximum compression, slowest.
public readonly environment: {[ key: string ]: string};
- Type: {[ key: string ]: string}
Custom environment variables to pass to the NextJS build and runtime.
public readonly isPlaceholder: boolean;
- Type: boolean
Skip building app and deploy a placeholder.
Useful when using next dev
for local development.
public readonly nodeEnv: string;
- Type: string
Optional value for NODE_ENV during build and runtime.
public readonly quiet: boolean;
- Type: boolean
Less build output.
public readonly tempBuildDir: string;
- Type: string
Directory to store temporary build files in.
Defaults to os.tmpdir().
public readonly nextBuild: NextjsBuild;
- Type: NextjsBuild
The NextjsBuild
instance representing the built Nextjs application.
public readonly bucket: IBucket | BucketProps;
- Type: aws-cdk-lib.aws_s3.IBucket | aws-cdk-lib.aws_s3.BucketProps
Properties for the S3 bucket containing the NextJS assets.
You can also supply your own bucket here.
public readonly distribution: IDistribution;
- Type: aws-cdk-lib.aws_cloudfront.IDistribution
Distribution to invalidate when assets change.
public readonly prune: boolean;
- Type: boolean
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.
Common props shared across NextJS-related CDK constructs.
import { NextjsBaseProps } from 'cdk-nextjs-standalone'
const nextjsBaseProps: NextjsBaseProps = { ... }
Name | Type | Description |
---|---|---|
nextjsPath |
string |
Relative path to the directory where the NextJS project is located. |
compressionLevel |
number |
0 - no compression, fatest 9 - maximum compression, slowest. |
environment |
{[ key: string ]: string} |
Custom environment variables to pass to the NextJS build and runtime. |
isPlaceholder |
boolean |
Skip building app and deploy a placeholder. |
nodeEnv |
string |
Optional value for NODE_ENV during build and runtime. |
quiet |
boolean |
Less build output. |
tempBuildDir |
string |
Directory to store temporary build files in. |
public readonly nextjsPath: string;
- Type: string
Relative path to the directory where the NextJS project is located.
Can be the root of your project (.
) or a subdirectory (packages/web
).
public readonly compressionLevel: number;
- Type: number
- Default: 1
0 - no compression, fatest 9 - maximum compression, slowest.
public readonly environment: {[ key: string ]: string};
- Type: {[ key: string ]: string}
Custom environment variables to pass to the NextJS build and runtime.
public readonly isPlaceholder: boolean;
- Type: boolean
Skip building app and deploy a placeholder.
Useful when using next dev
for local development.
public readonly nodeEnv: string;
- Type: string
Optional value for NODE_ENV during build and runtime.
public readonly quiet: boolean;
- Type: boolean
Less build output.
public readonly tempBuildDir: string;
- Type: string
Directory to store temporary build files in.
Defaults to os.tmpdir().
import { NextjsBuildProps } from 'cdk-nextjs-standalone'
const nextjsBuildProps: NextjsBuildProps = { ... }
Name | Type | Description |
---|---|---|
nextjsPath |
string |
Relative path to the directory where the NextJS project is located. |
compressionLevel |
number |
0 - no compression, fatest 9 - maximum compression, slowest. |
environment |
{[ key: string ]: string} |
Custom environment variables to pass to the NextJS build and runtime. |
isPlaceholder |
boolean |
Skip building app and deploy a placeholder. |
nodeEnv |
string |
Optional value for NODE_ENV during build and runtime. |
quiet |
boolean |
Less build output. |
tempBuildDir |
string |
Directory to store temporary build files in. |
public readonly nextjsPath: string;
- Type: string
Relative path to the directory where the NextJS project is located.
Can be the root of your project (.
) or a subdirectory (packages/web
).
public readonly compressionLevel: number;
- Type: number
- Default: 1
0 - no compression, fatest 9 - maximum compression, slowest.
public readonly environment: {[ key: string ]: string};
- Type: {[ key: string ]: string}
Custom environment variables to pass to the NextJS build and runtime.
public readonly isPlaceholder: boolean;
- Type: boolean
Skip building app and deploy a placeholder.
Useful when using next dev
for local development.
public readonly nodeEnv: string;
- Type: string
Optional value for NODE_ENV during build and runtime.
public readonly quiet: boolean;
- Type: boolean
Less build output.
public readonly tempBuildDir: string;
- Type: string
Directory to store temporary build files in.
Defaults to os.tmpdir().
import { NextjsCachePolicyProps } from 'cdk-nextjs-standalone'
const nextjsCachePolicyProps: NextjsCachePolicyProps = { ... }
Name | Type | Description |
---|---|---|
imageCachePolicy |
aws-cdk-lib.aws_cloudfront.ICachePolicy |
No description. |
lambdaCachePolicy |
aws-cdk-lib.aws_cloudfront.ICachePolicy |
No description. |
staticCachePolicy |
aws-cdk-lib.aws_cloudfront.ICachePolicy |
No description. |
public readonly imageCachePolicy: ICachePolicy;
- Type: aws-cdk-lib.aws_cloudfront.ICachePolicy
public readonly lambdaCachePolicy: ICachePolicy;
- Type: aws-cdk-lib.aws_cloudfront.ICachePolicy
public readonly staticCachePolicy: ICachePolicy;
- Type: aws-cdk-lib.aws_cloudfront.ICachePolicy
import { NextjsCdkDistributionProps } from 'cdk-nextjs-standalone'
const nextjsCdkDistributionProps: NextjsCdkDistributionProps = { ... }
Name | Type | Description |
---|---|---|
defaultBehavior |
aws-cdk-lib.aws_cloudfront.BehaviorOptions |
The default behavior for the distribution. |
additionalBehaviors |
{[ key: string ]: aws-cdk-lib.aws_cloudfront.BehaviorOptions} |
Additional behaviors for the distribution, mapped by the pathPattern that specifies which requests to apply the behavior to. |
certificate |
aws-cdk-lib.aws_certificatemanager.ICertificate |
A certificate to associate with the distribution. |
comment |
string |
Any comments you want to include about the distribution. |
defaultRootObject |
string |
The object that you want CloudFront to request from your origin (for example, index.html) when a viewer requests the root URL for your distribution. If no default object is set, the request goes to the origin's root (e.g., example.com/). |
domainNames |
string[] |
Alternative domain names for this distribution. |
enabled |
boolean |
Enable or disable the distribution. |
enableIpv6 |
boolean |
Whether CloudFront will respond to IPv6 DNS requests with an IPv6 address. |
enableLogging |
boolean |
Enable access logging for the distribution. |
errorResponses |
aws-cdk-lib.aws_cloudfront.ErrorResponse[] |
How CloudFront should handle requests that are not successful (e.g., PageNotFound). |
geoRestriction |
aws-cdk-lib.aws_cloudfront.GeoRestriction |
Controls the countries in which your content is distributed. |
httpVersion |
aws-cdk-lib.aws_cloudfront.HttpVersion |
Specify the maximum HTTP version that you want viewers to use to communicate with CloudFront. |
logBucket |
aws-cdk-lib.aws_s3.IBucket |
The Amazon S3 bucket to store the access logs in. |
logFilePrefix |
string |
An optional string that you want CloudFront to prefix to the access log filenames for this distribution. |
logIncludesCookies |
boolean |
Specifies whether you want CloudFront to include cookies in access logs. |
minimumProtocolVersion |
aws-cdk-lib.aws_cloudfront.SecurityPolicyProtocol |
The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections. |
priceClass |
aws-cdk-lib.aws_cloudfront.PriceClass |
The price class that corresponds with the maximum price that you want to pay for CloudFront service. |
sslSupportMethod |
aws-cdk-lib.aws_cloudfront.SSLMethod |
The SSL method CloudFront will use for your distribution. |
webAclId |
string |
Unique identifier that specifies the AWS WAF web ACL to associate with this CloudFront distribution. |
public readonly defaultBehavior: BehaviorOptions;
- Type: aws-cdk-lib.aws_cloudfront.BehaviorOptions
The default behavior for the distribution.
public readonly additionalBehaviors: {[ key: string ]: BehaviorOptions};
- Type: {[ key: string ]: aws-cdk-lib.aws_cloudfront.BehaviorOptions}
- Default: no additional behaviors are added.
Additional behaviors for the distribution, mapped by the pathPattern that specifies which requests to apply the behavior to.
public readonly certificate: ICertificate;
- Type: aws-cdk-lib.aws_certificatemanager.ICertificate
- Default: the CloudFront wildcard certificate (*.cloudfront.net) will be used.
A certificate to associate with the distribution.
The certificate must be located in N. Virginia (us-east-1).
public readonly comment: string;
- Type: string
- Default: no comment
Any comments you want to include about the distribution.
public readonly defaultRootObject: string;
- Type: string
- Default: no default root object
The object that you want CloudFront to request from your origin (for example, index.html) when a viewer requests the root URL for your distribution. If no default object is set, the request goes to the origin's root (e.g., example.com/).
public readonly domainNames: string[];
- Type: string[]
- Default: The distribution will only support the default generated name (e.g., d111111abcdef8.cloudfront.net)
Alternative domain names for this distribution.
If you want to use your own domain name, such as www.example.com, instead of the cloudfront.net domain name, you can add an alternate domain name to your distribution. If you attach a certificate to the distribution, you must add (at least one of) the domain names of the certificate to this list.
public readonly enabled: boolean;
- Type: boolean
- Default: true
Enable or disable the distribution.
public readonly enableIpv6: boolean;
- Type: boolean
- Default: true
Whether CloudFront will respond to IPv6 DNS requests with an IPv6 address.
If you specify false, CloudFront responds to IPv6 DNS requests with the DNS response code NOERROR and with no IP addresses. This allows viewers to submit a second request, for an IPv4 address for your distribution.
public readonly enableLogging: boolean;
- Type: boolean
- Default: false, unless
logBucket
is specified.
Enable access logging for the distribution.
public readonly errorResponses: ErrorResponse[];
- Type: aws-cdk-lib.aws_cloudfront.ErrorResponse[]
- Default: No custom error responses.
How CloudFront should handle requests that are not successful (e.g., PageNotFound).
public readonly geoRestriction: GeoRestriction;
- Type: aws-cdk-lib.aws_cloudfront.GeoRestriction
- Default: No geographic restrictions
Controls the countries in which your content is distributed.
public readonly httpVersion: HttpVersion;
- Type: aws-cdk-lib.aws_cloudfront.HttpVersion
- Default: HttpVersion.HTTP2
Specify the maximum HTTP version that you want viewers to use to communicate with CloudFront.
For viewers and CloudFront to use HTTP/2, viewers must support TLS 1.2 or later, and must support server name identification (SNI).
public readonly logBucket: IBucket;
- Type: aws-cdk-lib.aws_s3.IBucket
- Default: A bucket is created if
enableLogging
is true
The Amazon S3 bucket to store the access logs in.
public readonly logFilePrefix: string;
- Type: string
- Default: no prefix
An optional string that you want CloudFront to prefix to the access log filenames for this distribution.
public readonly logIncludesCookies: boolean;
- Type: boolean
- Default: false
Specifies whether you want CloudFront to include cookies in access logs.
public readonly minimumProtocolVersion: SecurityPolicyProtocol;
- Type: aws-cdk-lib.aws_cloudfront.SecurityPolicyProtocol
- Default: SecurityPolicyProtocol.TLS_V1_2_2021 if the '
The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections.
CloudFront serves your objects only to browsers or devices that support at least the SSL version that you specify.
public readonly priceClass: PriceClass;
- Type: aws-cdk-lib.aws_cloudfront.PriceClass
- Default: PriceClass.PRICE_CLASS_ALL
The price class that corresponds with the maximum price that you want to pay for CloudFront service.
If you specify PriceClass_All, CloudFront responds to requests for your objects from all CloudFront edge locations. If you specify a price class other than PriceClass_All, CloudFront serves your objects from the CloudFront edge location that has the lowest latency among the edge locations in your price class.
public readonly sslSupportMethod: SSLMethod;
- Type: aws-cdk-lib.aws_cloudfront.SSLMethod
- Default: SSLMethod.SNI
The SSL method CloudFront will use for your distribution.
Server Name Indication (SNI) - is an extension to the TLS computer networking protocol by which a client indicates which hostname it is attempting to connect to at the start of the handshaking process. This allows a server to present multiple certificates on the same IP address and TCP port number and hence allows multiple secure (HTTPS) websites (or any other service over TLS) to be served by the same IP address without requiring all those sites to use the same certificate.
CloudFront can use SNI to host multiple distributions on the same IP - which a large majority of clients will support.
If your clients cannot support SNI however - CloudFront can use dedicated IPs for your distribution - but there is a prorated monthly charge for using this feature. By default, we use SNI - but you can optionally enable dedicated IPs (VIP).
See the CloudFront SSL for more details about pricing : https://aws.amazon.com/cloudfront/custom-ssl-domains/
public readonly webAclId: string;
- Type: string
- Default: No AWS Web Application Firewall web access control list (web ACL).
Unique identifier that specifies the AWS WAF web ACL to associate with this CloudFront distribution.
To specify a web ACL created using the latest version of AWS WAF, use the ACL ARN, for example
arn:aws:wafv2:us-east-1:123456789012:global/webacl/ExampleWebACL/473e64fd-f30b-4765-81a0-62ad96dd167a
.
To specify a web ACL created using AWS WAF Classic, use the ACL ID, for example 473e64fd-f30b-4765-81a0-62ad96dd167a
.
Resources that will be created automatically if not supplied.
import { NextjsCdkProps } from 'cdk-nextjs-standalone'
const nextjsCdkProps: NextjsCdkProps = { ... }
Name | Type | Description |
---|---|---|
cachePolicies |
NextjsCachePolicyProps |
Override the default CloudFront cache policies created internally. |
deployment |
NextjsAssetsDeploymentProps |
Override static file deployment settings. |
distribution |
NextjsCdkDistributionProps |
Pass in a value to override the default settings this construct uses to create the CDK Distribution internally. |
lambda |
NextjsLambdaProps |
Override server lambda function settings. |
lambdaOriginRequestPolicy |
aws-cdk-lib.aws_cloudfront.IOriginRequestPolicy |
Override the default CloudFront lambda origin request policy created internally. |
public readonly cachePolicies: NextjsCachePolicyProps;
- Type: NextjsCachePolicyProps
Override the default CloudFront cache policies created internally.
public readonly deployment: NextjsAssetsDeploymentProps;
Override static file deployment settings.
public readonly distribution: NextjsCdkDistributionProps;
Pass in a value to override the default settings this construct uses to create the CDK Distribution
internally.
public readonly lambda: NextjsLambdaProps;
- Type: NextjsLambdaProps
Override server lambda function settings.
public readonly lambdaOriginRequestPolicy: IOriginRequestPolicy;
- Type: aws-cdk-lib.aws_cloudfront.IOriginRequestPolicy
Override the default CloudFront lambda origin request policy created internally.
import { NextjsDomainProps } from 'cdk-nextjs-standalone'
const nextjsDomainProps: NextjsDomainProps = { ... }
Name | Type | Description |
---|---|---|
domainName |
string |
The domain to be assigned to the website URL (ie. domain.com). |
alternateNames |
string[] |
Specify additional names that should route to the Cloudfront Distribution. |
certificate |
aws-cdk-lib.aws_certificatemanager.ICertificate |
Import the certificate for the domain. |
domainAlias |
string |
An alternative domain to be assigned to the website URL. |
hostedZone |
aws-cdk-lib.aws_route53.IHostedZone |
Import the underlying Route 53 hosted zone. |
isExternalDomain |
boolean |
Set this option if the domain is not hosted on Amazon Route 53. |
public readonly domainName: string;
- Type: string
The domain to be assigned to the website URL (ie. domain.com).
Supports domains that are hosted either on Route 53 or externally.
public readonly alternateNames: string[];
- Type: string[]
Specify additional names that should route to the Cloudfront Distribution.
Note, certificates for these names will not be automatically generated so the certificate
option must be specified.
public readonly certificate: ICertificate;
- Type: aws-cdk-lib.aws_certificatemanager.ICertificate
Import the certificate for the domain.
By default, SST will create a certificate with the domain name. The certificate will be created in the us-east-1
(N. Virginia) region as required by AWS CloudFront.
Set this option if you have an existing certificate in the us-east-1
region in AWS Certificate Manager you want to use.
public readonly domainAlias: string;
- Type: string
An alternative domain to be assigned to the website URL.
Visitors to the alias will be redirected to the main domain. (ie. www.domain.com
).
Use this to create a www.
version of your domain and redirect visitors to the root domain.
public readonly hostedZone: IHostedZone;
- Type: aws-cdk-lib.aws_route53.IHostedZone
Import the underlying Route 53 hosted zone.
public readonly isExternalDomain: boolean;
- Type: boolean
Set this option if the domain is not hosted on Amazon Route 53.
import { NextjsLambdaProps } from 'cdk-nextjs-standalone'
const nextjsLambdaProps: NextjsLambdaProps = { ... }
Name | Type | Description |
---|---|---|
nextjsPath |
string |
Relative path to the directory where the NextJS project is located. |
compressionLevel |
number |
0 - no compression, fatest 9 - maximum compression, slowest. |
environment |
{[ key: string ]: string} |
Custom environment variables to pass to the NextJS build and runtime. |
isPlaceholder |
boolean |
Skip building app and deploy a placeholder. |
nodeEnv |
string |
Optional value for NODE_ENV during build and runtime. |
quiet |
boolean |
Less build output. |
tempBuildDir |
string |
Directory to store temporary build files in. |
nextBuild |
NextjsBuild |
Built nextJS application. |
function |
aws-cdk-lib.aws_lambda.FunctionOptions |
Override function properties. |
public readonly nextjsPath: string;
- Type: string
Relative path to the directory where the NextJS project is located.
Can be the root of your project (.
) or a subdirectory (packages/web
).
public readonly compressionLevel: number;
- Type: number
- Default: 1
0 - no compression, fatest 9 - maximum compression, slowest.
public readonly environment: {[ key: string ]: string};
- Type: {[ key: string ]: string}
Custom environment variables to pass to the NextJS build and runtime.
public readonly isPlaceholder: boolean;
- Type: boolean
Skip building app and deploy a placeholder.
Useful when using next dev
for local development.
public readonly nodeEnv: string;
- Type: string
Optional value for NODE_ENV during build and runtime.
public readonly quiet: boolean;
- Type: boolean
Less build output.
public readonly tempBuildDir: string;
- Type: string
Directory to store temporary build files in.
Defaults to os.tmpdir().
public readonly nextBuild: NextjsBuild;
- Type: NextjsBuild
Built nextJS application.
public readonly function: FunctionOptions;
- Type: aws-cdk-lib.aws_lambda.FunctionOptions
Override function properties.
import { NextjsLayerProps } from 'cdk-nextjs-standalone'
const nextjsLayerProps: NextjsLayerProps = { ... }
import { NextjsProps } from 'cdk-nextjs-standalone'
const nextjsProps: NextjsProps = { ... }
Name | Type | Description |
---|---|---|
nextjsPath |
string |
Relative path to the directory where the NextJS project is located. |
compressionLevel |
number |
0 - no compression, fatest 9 - maximum compression, slowest. |
environment |
{[ key: string ]: string} |
Custom environment variables to pass to the NextJS build and runtime. |
isPlaceholder |
boolean |
Skip building app and deploy a placeholder. |
nodeEnv |
string |
Optional value for NODE_ENV during build and runtime. |
quiet |
boolean |
Less build output. |
tempBuildDir |
string |
Directory to store temporary build files in. |
cdk |
NextjsCdkProps |
Allows you to override default settings this construct uses internally to create the cloudfront distribution. |
customDomain |
string | NextjsDomainProps |
The customDomain for this website. Supports domains that are hosted either on Route 53 or externally. |
stageName |
string |
No description. |
waitForInvalidation |
boolean |
While deploying, waits for the CloudFront cache invalidation process to finish. |
public readonly nextjsPath: string;
- Type: string
Relative path to the directory where the NextJS project is located.
Can be the root of your project (.
) or a subdirectory (packages/web
).
public readonly compressionLevel: number;
- Type: number
- Default: 1
0 - no compression, fatest 9 - maximum compression, slowest.
public readonly environment: {[ key: string ]: string};
- Type: {[ key: string ]: string}
Custom environment variables to pass to the NextJS build and runtime.
public readonly isPlaceholder: boolean;
- Type: boolean
Skip building app and deploy a placeholder.
Useful when using next dev
for local development.
public readonly nodeEnv: string;
- Type: string
Optional value for NODE_ENV during build and runtime.
public readonly quiet: boolean;
- Type: boolean
Less build output.
public readonly tempBuildDir: string;
- Type: string
Directory to store temporary build files in.
Defaults to os.tmpdir().
public readonly cdk: NextjsCdkProps;
- Type: NextjsCdkProps
Allows you to override default settings this construct uses internally to create the cloudfront distribution.
public readonly customDomain: string | NextjsDomainProps;
- Type: string | NextjsDomainProps
The customDomain for this website. Supports domains that are hosted either on Route 53 or externally.
Note that you can also migrate externally hosted domains to Route 53 by following this guide.
Example
new Nextjs(this, "Web", {
nextjsPath: ".",
customDomain: "domain.com",
});
new Nextjs(this, "Web", {
nextjsPath: "packages/web", // monorepo: relative to the root of the CDK project
customDomain: {
domainName: "domain.com",
domainAlias: "www.domain.com",
hostedZone: "domain.com"
},
});
public readonly stageName: string;
- Type: string
public readonly waitForInvalidation: boolean;
- Type: boolean
While deploying, waits for the CloudFront cache invalidation process to finish.
This ensures that the new content will be served once the deploy command finishes. However, this process can sometimes take more than 5 mins. For non-prod environments it might make sense to pass in false
. That'll skip waiting for the cache to invalidate and speed up the deploy process.