cdk-nextjs 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +4 -4
- package/README.md +183 -2
- package/docs/1k-concurrent-users-executions.png +0 -0
- package/docs/cdk-nextjs-NextjsGlobalContainers.png +0 -0
- package/docs/cdk-nextjs-NextjsGlobalFunctions.png +0 -0
- package/docs/cdk-nextjs-NextjsRegionalContainers.png +0 -0
- package/docs/cdk-nextjs.drawio +89 -78
- package/docs/usage.xlsx +0 -0
- package/lib/nextjs-assets-deployment.js +1 -1
- package/lib/nextjs-build/nextjs-build.js +1 -1
- package/lib/nextjs-compute/nextjs-containers.js +1 -1
- package/lib/nextjs-compute/nextjs-functions.js +1 -1
- package/lib/nextjs-distribution.d.ts +1 -1
- package/lib/nextjs-distribution.js +3 -3
- package/lib/nextjs-file-system.js +1 -1
- package/lib/nextjs-post-deploy.js +1 -1
- package/lib/nextjs-static-assets.js +1 -1
- package/lib/nextjs-vpc.js +1 -1
- package/lib/root-constructs/nextjs-global-containers.js +1 -1
- package/lib/root-constructs/nextjs-global-functions.js +1 -1
- package/lib/root-constructs/nextjs-regional-containers.js +1 -1
- package/package.json +6 -6
package/.jsii
CHANGED
|
@@ -3964,7 +3964,7 @@
|
|
|
3964
3964
|
"stability": "stable"
|
|
3965
3965
|
},
|
|
3966
3966
|
"homepage": "https://github.com/cdklabs/cdk-nextjs.git",
|
|
3967
|
-
"jsiiVersion": "5.8.
|
|
3967
|
+
"jsiiVersion": "5.8.11 (build 55d251b)",
|
|
3968
3968
|
"keywords": [
|
|
3969
3969
|
"aws",
|
|
3970
3970
|
"aws-cdk",
|
|
@@ -3984,7 +3984,7 @@
|
|
|
3984
3984
|
},
|
|
3985
3985
|
"name": "cdk-nextjs",
|
|
3986
3986
|
"readme": {
|
|
3987
|
-
"markdown": "\n[](https://www.npmjs.org/package/cdk-nextjs)\n\n\n# CDK Next.js Construct Library\n\n<!--BEGIN STABILITY BANNER-->\n\n---\n\n\n\n> The APIs of higher level constructs in this module are experimental and under active development.\n> They are subject to non-backward compatible changes or removal in any future version. These are\n> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be\n> announced in the release notes. This means that while you may use them, you may need to update\n> your source code when upgrading to a newer version of this package.\n\n---\n\n<!--END STABILITY BANNER-->\n\nDeploy [Next.js](https://nextjs.org/) apps on [AWS](https://aws.amazon.com/) with the [AWS CDK](https://aws.amazon.com/cdk/).\n\n## Features\n\n- Supports all features of Next.js App and Pages Router for [Node.js Runtime](https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#nodejs-runtime). One exception is `NextjsGlobalFunctions` does not currently support [ISR](https://nextjs.org/docs/app/guides/incremental-static-regeneration) - waiting for [Official Next.js Deployment Adapters API](https://github.com/vercel/next.js/discussions/77740).\n- Choose your AWS architecture for Next.js with the supported constructs: `NextjsGlobalFunctions`, `NextjsGlobalContainers`, `NextjsRegionalContainers`.\n- Global Content Delivery Network (CDN) built with [Amazon CloudFront](https://aws.amazon.com/cloudfront/) to deliver content with low latency and high transfer speeds.\n- Serverless functions powered by [AWS Lambda](https://aws.amazon.com/lambda/) or serverless containers powered by [AWS Fargate](https://aws.amazon.com/fargate/).\n- Static assets (JS, CSS, public folder) are stored and served from [Amazon Simple Storage Service (S3)](https://aws.amazon.com/s3/) for global constructs to decrease latency and reduce compute costs.\n- [Optimized images](https://nextjs.org/docs/pages/building-your-application/optimizing/images), [data cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), and [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache) are shared across compute with [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/).\n- Customize every construct via `overrides`.\n- AWS security and operational best practices are utilized, guided by [cdk-nag](https://github.com/cdklabs/cdk-nag).\n- First class support for [monorepos](https://monorepo.tools/).\n- [AWS GovCloud (US)](https://aws.amazon.com/govcloud-us) compatible (with `NextjsRegionalContainers`).\n\n## Getting Started\n\n1. If you don’t have a Next.js project yet, follow [these steps](https://nextjs.org/docs/getting-started) to create one.\n1. Install [Docker](https://www.docker.com/). We recommend [Rancher Desktop](https://rancherdesktop.io/) with dockerd (moby) container engine enabled.\n1. Install [Node.js](https://nodejs.org/en). We recommend the long term support (LTS) version.\n1. Set your [next.config.js](https://nextjs.org/docs/pages/api-reference/next-config-js) [output](https://nextjs.org/docs/pages/api-reference/next-config-js/output) key to `\"standalone\"`. Learn more here about [Standalone Output](https://nextjs.org/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files).\n1. Setup [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) app.\n1. Install the construct package: `npm install cdk-nextjs`\n1. `cdk deploy`\n1. Visit URL printed in terminal (CloudFormation Output) to view your Next.js app!\n\n## Basic Example CDK App\n\n```ts\nimport { App, Stack, StackProps } from \"aws-cdk-lib\";\nimport { Construct } from \"constructs\";\nimport { NextjsGlobalFunctions } from \"cdk-nextjs\";\nimport { join } from \"node:path\";\n\nclass NextjsStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n new NextjsGlobalFunctions(this, \"Nextjs\", {\n healthCheckPath: \"/api/health\",\n buildContext: join(import.meta.dirname, \"..\"),\n });\n }\n}\n\nconst app = new App();\n\nnew NextjsStack(app, \"nextjs\");\n```\n\nSee [examples/](./examples/) for more usage examples.\n\n## Architecture\n\n### `NextjsGlobalFunctions`\n\nArchitecture includes [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) Functions to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this construct when you have unpredictable traffic, can afford occasional latency (i.e. cold starts - [typically 1% of production traffic](https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/)), and/or want the most granular pricing model. ([code](./src/root-constructs/nextjs-global-functions.ts#L81))\n\n\n\n### `NextjsGlobalContainers`\n\nArchitecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this option when you have predictable traffic, need the lowest latency, and/or can afford a less granular pricing model. ([code](./src/root-constructs/nextjs-global-containers.ts#L76))\n\n\n\n### `NextjsRegionalContainers`\n\nArchitecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/) to regionally serve requests. Use this options when you cannot use Amazon CloudFront (i.e. [AWS GovCloud](https://aws.amazon.com/govcloud-us/?whats-new.sort-by=item.additionalFields.postDateTime&whats-new.sort-order=desc)). ([code](./src/root-constructs/nextjs-regional-containers.ts#L41))\n\n\n\n## Why\n\nThe simplest path to deploy Next.js is on [Vercel](https://vercel.com/) - the Platform-as-a-Service company behind Next.js. However, deploying to Vercel can be expensive and some developers want all of their workloads running _directly_ on AWS. Developers can deploy Next.js on AWS through [AWS Amplify Hosting](https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplifysupport.html), but Amplify does not support all Next.js features and manages AWS resources for you so they cannot be customized. If Amplify meets your requirements we recommend you use it, but if you want to use all Next.js features or want more visibility into the AWS resources then this construct is for you.\n\n## Design Principles\n\n- Treat Next.js as black box. Minimize reliance on Next.js internal APIs to reduce chance of incompatibility between this construct and future versions of Next.js.\n- Security first.\n- One architecture does not fit all.\n- Enable customization everywhere.\n\n## Limitations\n\n- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers` (which use CloudFront), the number of top level files/directories cannot exceed 25, the max number of behaviors a CloudFront Distrubtion supports. We recommend you put all of your public assets into one top level directory (i.e. public/static) so you don't reach this limit. See [CloudFront Quotas](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html) for more information.\n- If using `NextjsGlobalFunctions`, when [revalidating data in Next.js](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation) (i.e. [revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath)), the CloudFront Cache will still hold stale data. You'll need to use AWS SDK JS V3 [CreateInvalidationCommand](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-cloudfront/Class/CreateInvalidationCommand/) to manually invalidate the path in CloudFront. See more [here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html).\n- If using `NextjsGlobalFunctions`, setting an Authorization header won't work by default because of Lambda Function URL with IAM Auth is already using the Authorization header. You can use the `AWS_LWA_AUTHORIZATION_SOURCE` environment variable of [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter) to set an alternative Authorization header in the client which will then be set to the Authorization header when it reaches your app.\n\n## Additional Security Recommendations\n\nThis construct by default implements all AWS security best practices that a CDK construct library reasonably can considering cost and complexity. Below are additional security practices we recommend you implement within your CDK app. Please see them below:\n\n- [VPC Flow Logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html). See [examples/](./examples) for sample implementation.\n- [Scan ECR Images For Vulnerabilities](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html).\n- For `NextjsGlobalFunctions` and `NextjsGlobalContainers`, [CloudFront Access Logs](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html). See [examples/](./examples) for sample implementation.\n- For `NextjsGlobalContainers` and `NextjsRegionalContainers`, [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)\n- If using `NextjsGlobalContainers`, enable `ReadonlyRootFilesystem`. This will remove ability to use Static On-Demand feature of Next.js so it's not enabled by default, but is recommended for security.\n\n## Estimated Costs\n\nWIP\n\n## Contributing\n\nSteps to build locally:\n\n1. `git clone https://github.com/cdklabs/cdk-nextjs.git`\n2. `cd cdk-nextjs`\n3. `pnpm i && pnpm compile && pnpm build`\n\nThis project uses Projen, so make sure to not edit [Projen](https://projen.io/) created files and only edit .projenrc.ts.\n\n## FAQ\n\nQ: How does this compare to [cdk-nextjs-standalone](https://github.com/jetbridge/cdk-nextjs)?<br/>\nA: cdk-nextjs-standalone relies on [OpenNext](https://github.com/sst/open-next). OpenNext injects custom code to interact with private Next.js APIs. While OpenNext is able to make some optimizations that are great for serverless environments, this comes at an increase maintenance cost and increased chances for breaking changes. A goal of cdk-nextjs is to customize Next.js as little as possible to reduce the maintenance burden and decrease chances of breaking changes.\n\nQ: Why not offer API Gateway version of construct?<br/>\nA: API Gateway does not support streaming.\n\nQ: Why EFS instead of S3?<br/>\nA: Next.js has 3 types of server caching that are persisted to disk: [Data Cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), [Full Route Cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache), and [Image Optimization](https://nextjs.org/docs/pages/building-your-application/optimizing/images). Cached data is persisted at .next/cache/fetch-cache, cached full routes are persisted at .next/server/app, and optimized images are persisted at .next/cache/images. Next.js provides a way to customize where cached data or cached full routes are persisted through the [Custom Next.js Cache Handler](https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath), but there currently is no way to persist optimized images. Therefore, we need a way to persist cached data at the file system level which is transparent to Next.js. To do this, we use [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/). Benefits of EFS include being able to cache any Next.js data persisted to disk and therefore being flexible to adapt to Next.js as the framework evolves caching additional types of data. One exception to not using the Custom Next.js Cache Handler is to support [Data Cache Time-based Revalidation](https://nextjs.org/docs/app/building-your-application/caching#time-based-revalidation) when using AWS Lambda functions. Functions only run when they are responding to a request preventing time-based revalidation unlike containers with AWS Fargate which run continually. For functions, an [Amazon SQS Queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) and consuming function that will make a HEAD request with x-prerender-revalidate header needed for Next.js to update cache.\n\nQ: How customizable is the `cdk-nextjs` package for different use cases?<br/>\nA: The `cdk-nextjs` package offers deep customization through _prop-based_ overrides. These can be accessed in the construct props, allowing you to override settings like VPC configurations, CloudFront distribution, and ECS/Fargate setup. For example, you can modify `nextjsBuildProps` to customize the build process or use `nextjsDistributionProps` to adjust how CloudFront handles caching and routing. This level of control makes it easy to adapt the infrastructure to your application’s specific performance, networking, or deployment needs.\n\nQ: How can I use a custom domain with `cdk-nextjs`?<br/>\nA: See [low-cost example](./examples/low-cost/app.ts).\n\nQ: What is difference between `NextjsGlobalFunctionsProps.overrides.nextjsDistribution` and `NextjsGlobalFunctionsProps.overrides.nextjsGlobalFunctions.nextjsDistributionProps`<br/>\nA: `NextjsGlobalFunctionsProps.overrides.nextjsDistribution` allows you to customize any construct's props _within_ `NextjsDistribution` and is likely what you want whereas `NextjsGlobalFunctionsProps.overrides.nextjsGlobalFunctions.nextjsDistributionProps` allows you to customize the props passed into the construct: `NextjsDistribution`. This principle also applies to other similarly named overrides.\n\nQ: Why use container image for `NextjsGlobalFunctions`?<br />\nA: Read [The case for containers on Lambda (with benchmarks)](https://aaronstuyvenberg.com/posts/containers-on-lambda).\n\n## Acknowledgements\n\nThis construct was built on the shoulders of giants. Thank you to the contributors of [cdk-nextjs-standalone](https://github.com/jetbridge/cdk-nextjs) and [open-next](https://github.com/sst/open-next).\n\n## 🥂 Thanks Contributors\n\nThank you for helping other developers deploy Next.js apps on AWS\n\n<a href=\"https://github.com/cdklabs/cdk-nextjs/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=cdklabs/cdk-nextjs\" />\n</a>\n"
|
|
3987
|
+
"markdown": "\n[](https://www.npmjs.org/package/cdk-nextjs)\n\n\n# CDK Next.js Construct Library\n\n<!--BEGIN STABILITY BANNER-->\n\n---\n\n\n\n> The APIs of higher level constructs in this module are experimental and under active development.\n> They are subject to non-backward compatible changes or removal in any future version. These are\n> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be\n> announced in the release notes. This means that while you may use them, you may need to update\n> your source code when upgrading to a newer version of this package.\n\n---\n\n<!--END STABILITY BANNER-->\n\nDeploy [Next.js](https://nextjs.org/) apps on [AWS](https://aws.amazon.com/) with the [AWS CDK](https://aws.amazon.com/cdk/).\n\n## Features\n\n- Supports all features of Next.js App and Pages Router for [Node.js Runtime](https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#nodejs-runtime). One exception is `NextjsGlobalFunctions` does not currently support [ISR](https://nextjs.org/docs/app/guides/incremental-static-regeneration) - waiting for [Official Next.js Deployment Adapters API](https://github.com/vercel/next.js/discussions/77740).\n- Choose your AWS architecture for Next.js with the supported constructs: `NextjsGlobalFunctions`, `NextjsGlobalContainers`, `NextjsRegionalContainers`.\n- Global Content Delivery Network (CDN) built with [Amazon CloudFront](https://aws.amazon.com/cloudfront/) to deliver content with low latency and high transfer speeds.\n- Serverless functions powered by [AWS Lambda](https://aws.amazon.com/lambda/) or serverless containers powered by [AWS Fargate](https://aws.amazon.com/fargate/).\n- Static assets (JS, CSS, public folder) are stored and served from [Amazon Simple Storage Service (S3)](https://aws.amazon.com/s3/) for global constructs to decrease latency and reduce compute costs.\n- [Optimized images](https://nextjs.org/docs/pages/building-your-application/optimizing/images), [data cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), and [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache) are shared across compute with [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/).\n- Customize every construct via `overrides`.\n- AWS security and operational best practices are utilized, guided by [cdk-nag](https://github.com/cdklabs/cdk-nag).\n- First class support for [monorepos](https://monorepo.tools/).\n- [AWS GovCloud (US)](https://aws.amazon.com/govcloud-us) compatible (with `NextjsRegionalContainers`).\n\n## Getting Started\n\n1. If you don’t have a Next.js project yet, follow [these steps](https://nextjs.org/docs/getting-started) to create one.\n1. Install [Docker](https://www.docker.com/). We recommend [Rancher Desktop](https://rancherdesktop.io/) with dockerd (moby) container engine enabled.\n1. Install [Node.js](https://nodejs.org/en). We recommend the long term support (LTS) version.\n1. Set your [next.config.js](https://nextjs.org/docs/pages/api-reference/next-config-js) [output](https://nextjs.org/docs/pages/api-reference/next-config-js/output) key to `\"standalone\"`. Learn more here about [Standalone Output](https://nextjs.org/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files).\n1. Setup [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) app.\n1. Install the construct package: `npm install cdk-nextjs`\n1. `cdk deploy`\n1. Visit URL printed in terminal (CloudFormation Output) to view your Next.js app!\n\n## Basic Example CDK App\n\n```ts\nimport { App, Stack, StackProps } from \"aws-cdk-lib\";\nimport { Construct } from \"constructs\";\nimport { NextjsGlobalFunctions } from \"cdk-nextjs\";\nimport { join } from \"node:path\";\n\nclass NextjsStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n new NextjsGlobalFunctions(this, \"Nextjs\", {\n healthCheckPath: \"/api/health\",\n buildContext: join(import.meta.dirname, \"..\"),\n });\n }\n}\n\nconst app = new App();\n\nnew NextjsStack(app, \"nextjs\");\n```\n\nSee [examples/](./examples/) for more usage examples.\n\n## Architecture\n\n### `NextjsGlobalFunctions`\n\nArchitecture includes [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) Functions to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this construct when you have unpredictable traffic, can afford occasional latency (i.e. cold starts - [typically 1% of production traffic](https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/)), and/or want the most granular pricing model. ([code](./src/root-constructs/nextjs-global-functions.ts#L81))\n\n\n\n### `NextjsGlobalContainers`\n\nArchitecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) Distribution to globally serve requests and distribute static assets. Use this option when you have predictable traffic, need the lowest latency, and/or can afford a less granular pricing model. ([code](./src/root-constructs/nextjs-global-containers.ts#L76))\n\n\n\n### `NextjsRegionalContainers`\n\nArchitecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html) containers to respond to dynamic requests and [Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/) to regionally serve requests. Use this options when you cannot use Amazon CloudFront (i.e. [AWS GovCloud](https://aws.amazon.com/govcloud-us/?whats-new.sort-by=item.additionalFields.postDateTime&whats-new.sort-order=desc)). ([code](./src/root-constructs/nextjs-regional-containers.ts#L41))\n\n\n\n## Why\n\nThe simplest path to deploy Next.js is on [Vercel](https://vercel.com/) - the Platform-as-a-Service company behind Next.js. However, deploying to Vercel can be expensive and some developers want all of their workloads running _directly_ on AWS. Developers can deploy Next.js on AWS through [AWS Amplify Hosting](https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplifysupport.html), but Amplify does not support all Next.js features and manages AWS resources for you so they cannot be customized. If Amplify meets your requirements we recommend you use it, but if you want to use all Next.js features or want more visibility into the AWS resources then this construct is for you.\n\n## Design Principles\n\n- Treat Next.js as black box. Minimize reliance on Next.js internal APIs to reduce chance of incompatibility between this construct and future versions of Next.js.\n- Security first.\n- One architecture does not fit all.\n- Enable customization everywhere.\n\n## Limitations\n\n- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers` (which use CloudFront), the number of top level files/directories cannot exceed 25, the max number of behaviors a CloudFront Distrubtion supports. We recommend you put all of your public assets into one top level directory (i.e. public/static) so you don't reach this limit. See [CloudFront Quotas](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html) for more information.\n- If using `NextjsGlobalFunctions`, when [revalidating data in Next.js](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation) (i.e. [revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath)), the CloudFront Cache will still hold stale data. You'll need to use AWS SDK JS V3 [CreateInvalidationCommand](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-cloudfront/Class/CreateInvalidationCommand/) to manually invalidate the path in CloudFront. See more [here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html).\n- If using `NextjsGlobalFunctions`, setting an Authorization header won't work by default because of Lambda Function URL with IAM Auth is already using the Authorization header. You can use the `AWS_LWA_AUTHORIZATION_SOURCE` environment variable of [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter) to set an alternative Authorization header in the client which will then be set to the Authorization header when it reaches your app.\n\n## Additional Security Recommendations\n\nThis construct by default implements all AWS security best practices that a CDK construct library reasonably can considering cost and complexity. Below are additional security practices we recommend you implement within your CDK app. Please see them below:\n\n- [VPC Flow Logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html). See [examples/](./examples) for sample implementation.\n- [Scan ECR Images For Vulnerabilities](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html).\n- For `NextjsGlobalFunctions` and `NextjsGlobalContainers`, [CloudFront Access Logs](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html). See [examples/](./examples) for sample implementation.\n- For `NextjsGlobalContainers` and `NextjsRegionalContainers`, [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)\n- If using `NextjsGlobalContainers`, enable `ReadonlyRootFilesystem`. This will remove ability to use Static On-Demand feature of Next.js so it's not enabled by default, but is recommended for security.\n\n## Estimated Costs\n\n### Assumptions\n\nThe following basic assumptions were used for a typical medium Next.js app. See [docs/usage.xlsx](./docs/usage.xlsx) for detailed assumptions and usage per construct type that you can plug into AWS Pricing Calculator.\n\n| Metric | Value |\n| ------------------------------------------------------------ | ----- |\n| Monthly Active Users | 1K |\n| Pages Visited Per Month Per User | 100 |\n| Avg Request Size | 50KB |\n| Static Requests Per Page (js, css, etc) | 15 |\n| Static Requests Cache Hit % | 50% |\n| Static Assets Size | 10GB |\n| Dynamic Requests Per Page (document, optimized images, etc.) | 5 |\n| Dynamic Cache Read % | 50% |\n| Dynamic Cache Write % | 5% |\n| Dynamic Cache Data Size | 10GB |\n| Average Dynamic Cache Request Size | 100KB |\n\nMore Details:\n\n- Assume ARM architecture for compute\n- AWS Region: us-east-1\n- Excludes charges related to: CloudWatch Logs, NAT Gateway data processing\n\n#### NAT Gateway and Alternatives\n\n[NAT Gateways](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) enable compute within private subnets to access the internet without directly exposing that compute to the internet. NAT Gateways prevent you from having to manage your own NAT Instances however they cost $0.045/hr/AZ resulting in charge of $64.80/month for 2 AZs (.045 x 24 x 30 x 2). While NAT Gateways are recommended by AWS to ensure maximum reliability and scalability, some customers may desire less expensive alternatives:\n\n1. $0.00 - if you're Next.js app does not need to access the internet, remove the NAT Gateway.\n2. $6.05 - managing your own [NAT Instance](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html). See [examples/low-cost](./examples/low-cost/) for how to use [fck-nat](https://fck-nat.dev/stable/).\n3. $32.40 - use 1 AZ instead of 2.\n\n### NextjsGlobalFunctions\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=cbabcb1142ad9b29345b82b33b3cf552eddc966a)\n\n| Service | Monthly Usage | Estimated Monthly Cost (USD) |\n| ---------- | ---------------------------------------------- | ---------------------------- |\n| Lambda | 500K requests, 2 GB memory, 150ms avg duration | $0.00 (Always Free Tier) |\n| CloudFront | 2M requests, 100 GB transfer to internet | $0.00 (Always Free Tier) |\n| S3 | 10 GB storage, 750K GET requests | $0.53 |\n| EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $3.90 |\n| VPC | NAT Gateway, 2 AZs | $64.80 |\n| Total | | $69.32 |\n\n### NextjsGlobalContainers\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=1354220e3d611a726139bee4af4277debacd365c)\n\n| Service | Monthly Usage | Estimated Monthly Cost (USD) |\n| ----------- | ---------------------------------------------- | ---------------------------- |\n| ECS Fargate | 1 task (1 vCPU, 2 GB) | $28.44 |\n| ALB | 1 LB, 1.04GB/hr, 5.79 conn/sec | $22.50 |\n| CloudFront | 2M requests, 100 GB transfer to internet | $0.00 (Always Free Tier) |\n| S3 | 10 GB storage, 750K GET requests | $0.53 |\n| EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $3.90 |\n| VPC | NAT Gateway, 2 AZs | $64.80 |\n| Total | | $120.53 |\n\n### NextjsRegionalContainers\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=f53440707350f74cf478ca9e45a3ad32f5e16710)\n\n| Service | Monthly Usage | Estimated Monthly Cost (USD) |\n| ----------- | ---------------------------------------------- | ---------------------------- |\n| ECS Fargate | 1 task (2 vCPU, 4 GB), always on | $28.44 |\n| ALB | 1 LB, 4.17 GB/hr, 23.15 conn/sec | $40.78 |\n| EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $4.05 |\n| VPC | NAT Gateway, 2 AZs | $64.80 |\n| Total | | $138.07 |\n\n## Performance\n\n[Artillery Playwright](https://www.artillery.io/docs/reference/engines/playwright#overview) app playground example load tests results with 1K concurrent users. Reproduce with `pnpm test-fargate:lg` within `examples/load-tests`.\n\n### NextjsGlobalFunctions\n\n<details>\n<summary>`NextjsGlobalFunctions` Performance Details</summary>\n\n```bash\nbrowser.page.TTFB.https://abc123.cloudfront.net/isr:\n min: ......................................................................... 6.3\n max: ......................................................................... 5017.4\n mean: ........................................................................ 11.5\n median: ...................................................................... 10.3\n p95: ......................................................................... 15.6\n p99: ......................................................................... 22.9\nbrowser.page.TTFB.https://abc123.cloudfront.net/isr/1:\n min: ......................................................................... 3.2\n max: ......................................................................... 560.6\n mean: ........................................................................ 9.4\n median: ...................................................................... 5.4\n p95: ......................................................................... 11.1\n p99: ......................................................................... 162.4\nbrowser.page.TTFB.https://abc123.cloudfront.net/isr/2:\n min: ......................................................................... 3.1\n max: ......................................................................... 1511.9\n mean: ........................................................................ 9.2\n median: ...................................................................... 5.2\n p95: ......................................................................... 10.7\n p99: ......................................................................... 149.9\nbrowser.page.TTFB.https://abc123.cloudfront.net/isr/3:\n min: ......................................................................... 3.4\n max: ......................................................................... 131.1\n mean: ........................................................................ 7.1\n median: ...................................................................... 5.3\n p95: ......................................................................... 10.1\n p99: ......................................................................... 64.7\nbrowser.page.TTFB.https://abc123.cloudfront.net/ssg:\n min: ......................................................................... 6.4\n max: ......................................................................... 5015.1\n mean: ........................................................................ 11.5\n median: ...................................................................... 10.3\n p95: ......................................................................... 15.6\n p99: ......................................................................... 23.3\nbrowser.page.TTFB.https://abc123.cloudfront.net/ssg/3:\n min: ......................................................................... 2.9\n max: ......................................................................... 98\n mean: ........................................................................ 5.1\n median: ...................................................................... 4.6\n p95: ......................................................................... 8.2\n p99: ......................................................................... 12.8\nbrowser.page.TTFB.https://abc123.cloudfront.net/ssr:\n min: ......................................................................... 6.4\n max: ......................................................................... 5018.6\n mean: ........................................................................ 11.3\n median: ...................................................................... 10.3\n p95: ......................................................................... 15.6\n p99: ......................................................................... 23.3\nbrowser.page.TTFB.https://abc123.cloudfront.net/ssr/2:\n min: ......................................................................... 83.4\n max: ......................................................................... 150.7\n mean: ........................................................................ 119\n median: ...................................................................... 111.1\n p95: ......................................................................... 147\n p99: ......................................................................... 147\nbrowser.page.TTFB.https://abc123.cloudfront.net/streaming:\n min: ......................................................................... 6.4\n max: ......................................................................... 5015.2\n mean: ........................................................................ 11.8\n median: ...................................................................... 10.3\n p95: ......................................................................... 15.6\n p99: ......................................................................... 23.3\n```\n\n</details>\n\n\n\n### NextjsGlobalContainers\n\n<details>\n<summary>`NextjsGlobalContainers` Performance Details</summary>\n\n```bash\nTODO\n```\n\n</details>\n\n### NextjsRegionalContainers\n\n<details>\n<summary>`NextjsRegionalContainers` Performance Details</summary>\n\n```bash\nTODO\n```\n\n</details>\n\n## Contributing\n\nSteps to build locally:\n\n1. `git clone https://github.com/cdklabs/cdk-nextjs.git`\n2. `cd cdk-nextjs`\n3. `pnpm i && pnpm compile && pnpm build`\n\nThis project uses Projen, so make sure to not edit [Projen](https://projen.io/) created files and only edit .projenrc.ts.\n\n## FAQ\n\nQ: How does this compare to [cdk-nextjs-standalone](https://github.com/jetbridge/cdk-nextjs)?<br/>\nA: cdk-nextjs-standalone relies on [OpenNext](https://github.com/sst/open-next). OpenNext injects custom code to interact with private Next.js APIs. While OpenNext is able to make some optimizations that are great for serverless environments, this comes at an increase maintenance cost and increased chances for breaking changes. A goal of cdk-nextjs is to customize Next.js as little as possible to reduce the maintenance burden and decrease chances of breaking changes.\n\nQ: Why not offer API Gateway version of construct?<br/>\nA: API Gateway does not support streaming.\n\nQ: How does cdk-nextjs support caching in Next.js?<br/>\nA: Next.js has 3 types of server caching that are persisted to disk: [data cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache), and [image optimization cache](https://nextjs.org/docs/pages/building-your-application/optimizing/images). By default this cached data is persisted on individual compute instances and is not shared - reducing cache hits. cdk-nextjs uses the [custom Next.js cache handler](https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath) for data and full route cache and symlinking for image optimization cache to modify Next.js to read/write from a mounted file system\n\nQ: Why EFS instead of S3?<br/>\nA: cdk-nextjs uses [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/) to mount a file system to functions or containers as a shared cache. The custom Next.js cache handler could be modified to read/write data to [Amazon S3](https://aws.amazon.com/pm/serv-s3), but there is no way to modify the location of the image optimization cache without modifying Next.js internals. Other factors to compare:\n\n| Factor | EFS | S3 |\n| ----------------------------- | ------------------------- | --------------------- |\n| Performance | 1-10ms per file operation | 100-200ms per request |\n| Cold Start Impact | 50-100ms to mount | No impact |\n| Storage Cost | $0.30 / GB-month | $0.023 / GB-month |\n| Read Throughput/Request Cost | $0.03 / GB-month | $0.04 / M requests |\n| Write Throughput/Request Cost | $0.06 / GB-month | $5.00 / M requests |\n\nQ: How customizable is the `cdk-nextjs` package for different use cases?<br/>\nA: The `cdk-nextjs` package offers deep customization through _prop-based_ overrides. These can be accessed in the construct props, allowing you to override settings like VPC configurations, CloudFront distribution, and ECS/Fargate setup. For example, you can modify `nextjsBuildProps` to customize the build process or use `nextjsDistributionProps` to adjust how CloudFront handles caching and routing. This level of control makes it easy to adapt the infrastructure to your application’s specific performance, networking, or deployment needs.\n\nQ: How can I use a custom domain with `cdk-nextjs`?<br/>\nA: See [low-cost example](./examples/low-cost/app.ts).\n\nQ: What is difference between `NextjsGlobalFunctionsProps.overrides.nextjsDistribution` and `NextjsGlobalFunctionsProps.overrides.nextjsGlobalFunctions.nextjsDistributionProps`<br/>\nA: `NextjsGlobalFunctionsProps.overrides.nextjsDistribution` allows you to customize any construct's props _within_ `NextjsDistribution` and is likely what you want whereas `NextjsGlobalFunctionsProps.overrides.nextjsGlobalFunctions.nextjsDistributionProps` allows you to customize the props passed into the construct: `NextjsDistribution`. This principle also applies to other similarly named overrides.\n\nQ: Why use container image for `NextjsGlobalFunctions`?<br />\nA: Read [The case for containers on Lambda (with benchmarks)](https://aaronstuyvenberg.com/posts/containers-on-lambda).\n\n## Acknowledgements\n\nThis construct was built on the shoulders of giants. Thank you to the contributors of [cdk-nextjs-standalone](https://github.com/jetbridge/cdk-nextjs) and [open-next](https://github.com/sst/open-next).\n\n## 🥂 Thanks Contributors\n\nThank you for helping other developers deploy Next.js apps on AWS\n\n<a href=\"https://github.com/cdklabs/cdk-nextjs/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=cdklabs/cdk-nextjs\" />\n</a>\n"
|
|
3988
3988
|
},
|
|
3989
3989
|
"repository": {
|
|
3990
3990
|
"type": "git",
|
|
@@ -14399,6 +14399,6 @@
|
|
|
14399
14399
|
"symbolId": "src/nextjs-build/nextjs-build:PublicDirEntry"
|
|
14400
14400
|
}
|
|
14401
14401
|
},
|
|
14402
|
-
"version": "0.4.
|
|
14403
|
-
"fingerprint": "
|
|
14402
|
+
"version": "0.4.2",
|
|
14403
|
+
"fingerprint": "yE73lbdN5N5mIeiO7ipZOFVfjUpSZ2q+34Lq+IzP/48="
|
|
14404
14404
|
}
|
package/README.md
CHANGED
|
@@ -120,7 +120,177 @@ This construct by default implements all AWS security best practices that a CDK
|
|
|
120
120
|
|
|
121
121
|
## Estimated Costs
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
### Assumptions
|
|
124
|
+
|
|
125
|
+
The following basic assumptions were used for a typical medium Next.js app. See [docs/usage.xlsx](./docs/usage.xlsx) for detailed assumptions and usage per construct type that you can plug into AWS Pricing Calculator.
|
|
126
|
+
|
|
127
|
+
| Metric | Value |
|
|
128
|
+
| ------------------------------------------------------------ | ----- |
|
|
129
|
+
| Monthly Active Users | 1K |
|
|
130
|
+
| Pages Visited Per Month Per User | 100 |
|
|
131
|
+
| Avg Request Size | 50KB |
|
|
132
|
+
| Static Requests Per Page (js, css, etc) | 15 |
|
|
133
|
+
| Static Requests Cache Hit % | 50% |
|
|
134
|
+
| Static Assets Size | 10GB |
|
|
135
|
+
| Dynamic Requests Per Page (document, optimized images, etc.) | 5 |
|
|
136
|
+
| Dynamic Cache Read % | 50% |
|
|
137
|
+
| Dynamic Cache Write % | 5% |
|
|
138
|
+
| Dynamic Cache Data Size | 10GB |
|
|
139
|
+
| Average Dynamic Cache Request Size | 100KB |
|
|
140
|
+
|
|
141
|
+
More Details:
|
|
142
|
+
|
|
143
|
+
- Assume ARM architecture for compute
|
|
144
|
+
- AWS Region: us-east-1
|
|
145
|
+
- Excludes charges related to: CloudWatch Logs, NAT Gateway data processing
|
|
146
|
+
|
|
147
|
+
#### NAT Gateway and Alternatives
|
|
148
|
+
|
|
149
|
+
[NAT Gateways](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) enable compute within private subnets to access the internet without directly exposing that compute to the internet. NAT Gateways prevent you from having to manage your own NAT Instances however they cost $0.045/hr/AZ resulting in charge of $64.80/month for 2 AZs (.045 x 24 x 30 x 2). While NAT Gateways are recommended by AWS to ensure maximum reliability and scalability, some customers may desire less expensive alternatives:
|
|
150
|
+
|
|
151
|
+
1. $0.00 - if you're Next.js app does not need to access the internet, remove the NAT Gateway.
|
|
152
|
+
2. $6.05 - managing your own [NAT Instance](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html). See [examples/low-cost](./examples/low-cost/) for how to use [fck-nat](https://fck-nat.dev/stable/).
|
|
153
|
+
3. $32.40 - use 1 AZ instead of 2.
|
|
154
|
+
|
|
155
|
+
### NextjsGlobalFunctions
|
|
156
|
+
|
|
157
|
+
[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=cbabcb1142ad9b29345b82b33b3cf552eddc966a)
|
|
158
|
+
|
|
159
|
+
| Service | Monthly Usage | Estimated Monthly Cost (USD) |
|
|
160
|
+
| ---------- | ---------------------------------------------- | ---------------------------- |
|
|
161
|
+
| Lambda | 500K requests, 2 GB memory, 150ms avg duration | $0.00 (Always Free Tier) |
|
|
162
|
+
| CloudFront | 2M requests, 100 GB transfer to internet | $0.00 (Always Free Tier) |
|
|
163
|
+
| S3 | 10 GB storage, 750K GET requests | $0.53 |
|
|
164
|
+
| EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $3.90 |
|
|
165
|
+
| VPC | NAT Gateway, 2 AZs | $64.80 |
|
|
166
|
+
| Total | | $69.32 |
|
|
167
|
+
|
|
168
|
+
### NextjsGlobalContainers
|
|
169
|
+
|
|
170
|
+
[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=1354220e3d611a726139bee4af4277debacd365c)
|
|
171
|
+
|
|
172
|
+
| Service | Monthly Usage | Estimated Monthly Cost (USD) |
|
|
173
|
+
| ----------- | ---------------------------------------------- | ---------------------------- |
|
|
174
|
+
| ECS Fargate | 1 task (1 vCPU, 2 GB) | $28.44 |
|
|
175
|
+
| ALB | 1 LB, 1.04GB/hr, 5.79 conn/sec | $22.50 |
|
|
176
|
+
| CloudFront | 2M requests, 100 GB transfer to internet | $0.00 (Always Free Tier) |
|
|
177
|
+
| S3 | 10 GB storage, 750K GET requests | $0.53 |
|
|
178
|
+
| EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $3.90 |
|
|
179
|
+
| VPC | NAT Gateway, 2 AZs | $64.80 |
|
|
180
|
+
| Total | | $120.53 |
|
|
181
|
+
|
|
182
|
+
### NextjsRegionalContainers
|
|
183
|
+
|
|
184
|
+
[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=f53440707350f74cf478ca9e45a3ad32f5e16710)
|
|
185
|
+
|
|
186
|
+
| Service | Monthly Usage | Estimated Monthly Cost (USD) |
|
|
187
|
+
| ----------- | ---------------------------------------------- | ---------------------------- |
|
|
188
|
+
| ECS Fargate | 1 task (2 vCPU, 4 GB), always on | $28.44 |
|
|
189
|
+
| ALB | 1 LB, 4.17 GB/hr, 23.15 conn/sec | $40.78 |
|
|
190
|
+
| EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $4.05 |
|
|
191
|
+
| VPC | NAT Gateway, 2 AZs | $64.80 |
|
|
192
|
+
| Total | | $138.07 |
|
|
193
|
+
|
|
194
|
+
## Performance
|
|
195
|
+
|
|
196
|
+
[Artillery Playwright](https://www.artillery.io/docs/reference/engines/playwright#overview) app playground example load tests results with 1K concurrent users. Reproduce with `pnpm test-fargate:lg` within `examples/load-tests`.
|
|
197
|
+
|
|
198
|
+
### NextjsGlobalFunctions
|
|
199
|
+
|
|
200
|
+
<details>
|
|
201
|
+
<summary>`NextjsGlobalFunctions` Performance Details</summary>
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
browser.page.TTFB.https://abc123.cloudfront.net/isr:
|
|
205
|
+
min: ......................................................................... 6.3
|
|
206
|
+
max: ......................................................................... 5017.4
|
|
207
|
+
mean: ........................................................................ 11.5
|
|
208
|
+
median: ...................................................................... 10.3
|
|
209
|
+
p95: ......................................................................... 15.6
|
|
210
|
+
p99: ......................................................................... 22.9
|
|
211
|
+
browser.page.TTFB.https://abc123.cloudfront.net/isr/1:
|
|
212
|
+
min: ......................................................................... 3.2
|
|
213
|
+
max: ......................................................................... 560.6
|
|
214
|
+
mean: ........................................................................ 9.4
|
|
215
|
+
median: ...................................................................... 5.4
|
|
216
|
+
p95: ......................................................................... 11.1
|
|
217
|
+
p99: ......................................................................... 162.4
|
|
218
|
+
browser.page.TTFB.https://abc123.cloudfront.net/isr/2:
|
|
219
|
+
min: ......................................................................... 3.1
|
|
220
|
+
max: ......................................................................... 1511.9
|
|
221
|
+
mean: ........................................................................ 9.2
|
|
222
|
+
median: ...................................................................... 5.2
|
|
223
|
+
p95: ......................................................................... 10.7
|
|
224
|
+
p99: ......................................................................... 149.9
|
|
225
|
+
browser.page.TTFB.https://abc123.cloudfront.net/isr/3:
|
|
226
|
+
min: ......................................................................... 3.4
|
|
227
|
+
max: ......................................................................... 131.1
|
|
228
|
+
mean: ........................................................................ 7.1
|
|
229
|
+
median: ...................................................................... 5.3
|
|
230
|
+
p95: ......................................................................... 10.1
|
|
231
|
+
p99: ......................................................................... 64.7
|
|
232
|
+
browser.page.TTFB.https://abc123.cloudfront.net/ssg:
|
|
233
|
+
min: ......................................................................... 6.4
|
|
234
|
+
max: ......................................................................... 5015.1
|
|
235
|
+
mean: ........................................................................ 11.5
|
|
236
|
+
median: ...................................................................... 10.3
|
|
237
|
+
p95: ......................................................................... 15.6
|
|
238
|
+
p99: ......................................................................... 23.3
|
|
239
|
+
browser.page.TTFB.https://abc123.cloudfront.net/ssg/3:
|
|
240
|
+
min: ......................................................................... 2.9
|
|
241
|
+
max: ......................................................................... 98
|
|
242
|
+
mean: ........................................................................ 5.1
|
|
243
|
+
median: ...................................................................... 4.6
|
|
244
|
+
p95: ......................................................................... 8.2
|
|
245
|
+
p99: ......................................................................... 12.8
|
|
246
|
+
browser.page.TTFB.https://abc123.cloudfront.net/ssr:
|
|
247
|
+
min: ......................................................................... 6.4
|
|
248
|
+
max: ......................................................................... 5018.6
|
|
249
|
+
mean: ........................................................................ 11.3
|
|
250
|
+
median: ...................................................................... 10.3
|
|
251
|
+
p95: ......................................................................... 15.6
|
|
252
|
+
p99: ......................................................................... 23.3
|
|
253
|
+
browser.page.TTFB.https://abc123.cloudfront.net/ssr/2:
|
|
254
|
+
min: ......................................................................... 83.4
|
|
255
|
+
max: ......................................................................... 150.7
|
|
256
|
+
mean: ........................................................................ 119
|
|
257
|
+
median: ...................................................................... 111.1
|
|
258
|
+
p95: ......................................................................... 147
|
|
259
|
+
p99: ......................................................................... 147
|
|
260
|
+
browser.page.TTFB.https://abc123.cloudfront.net/streaming:
|
|
261
|
+
min: ......................................................................... 6.4
|
|
262
|
+
max: ......................................................................... 5015.2
|
|
263
|
+
mean: ........................................................................ 11.8
|
|
264
|
+
median: ...................................................................... 10.3
|
|
265
|
+
p95: ......................................................................... 15.6
|
|
266
|
+
p99: ......................................................................... 23.3
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
</details>
|
|
270
|
+
|
|
271
|
+

|
|
272
|
+
|
|
273
|
+
### NextjsGlobalContainers
|
|
274
|
+
|
|
275
|
+
<details>
|
|
276
|
+
<summary>`NextjsGlobalContainers` Performance Details</summary>
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
TODO
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
</details>
|
|
283
|
+
|
|
284
|
+
### NextjsRegionalContainers
|
|
285
|
+
|
|
286
|
+
<details>
|
|
287
|
+
<summary>`NextjsRegionalContainers` Performance Details</summary>
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
TODO
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
</details>
|
|
124
294
|
|
|
125
295
|
## Contributing
|
|
126
296
|
|
|
@@ -140,8 +310,19 @@ A: cdk-nextjs-standalone relies on [OpenNext](https://github.com/sst/open-next).
|
|
|
140
310
|
Q: Why not offer API Gateway version of construct?<br/>
|
|
141
311
|
A: API Gateway does not support streaming.
|
|
142
312
|
|
|
313
|
+
Q: How does cdk-nextjs support caching in Next.js?<br/>
|
|
314
|
+
A: Next.js has 3 types of server caching that are persisted to disk: [data cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache), and [image optimization cache](https://nextjs.org/docs/pages/building-your-application/optimizing/images). By default this cached data is persisted on individual compute instances and is not shared - reducing cache hits. cdk-nextjs uses the [custom Next.js cache handler](https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath) for data and full route cache and symlinking for image optimization cache to modify Next.js to read/write from a mounted file system
|
|
315
|
+
|
|
143
316
|
Q: Why EFS instead of S3?<br/>
|
|
144
|
-
A:
|
|
317
|
+
A: cdk-nextjs uses [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/) to mount a file system to functions or containers as a shared cache. The custom Next.js cache handler could be modified to read/write data to [Amazon S3](https://aws.amazon.com/pm/serv-s3), but there is no way to modify the location of the image optimization cache without modifying Next.js internals. Other factors to compare:
|
|
318
|
+
|
|
319
|
+
| Factor | EFS | S3 |
|
|
320
|
+
| ----------------------------- | ------------------------- | --------------------- |
|
|
321
|
+
| Performance | 1-10ms per file operation | 100-200ms per request |
|
|
322
|
+
| Cold Start Impact | 50-100ms to mount | No impact |
|
|
323
|
+
| Storage Cost | $0.30 / GB-month | $0.023 / GB-month |
|
|
324
|
+
| Read Throughput/Request Cost | $0.03 / GB-month | $0.04 / M requests |
|
|
325
|
+
| Write Throughput/Request Cost | $0.06 / GB-month | $5.00 / M requests |
|
|
145
326
|
|
|
146
327
|
Q: How customizable is the `cdk-nextjs` package for different use cases?<br/>
|
|
147
328
|
A: The `cdk-nextjs` package offers deep customization through _prop-based_ overrides. These can be accessed in the construct props, allowing you to override settings like VPC configurations, CloudFront distribution, and ECS/Fargate setup. For example, you can modify `nextjsBuildProps` to customize the build process or use `nextjsDistributionProps` to adjust how CloudFront handles caching and routing. This level of control makes it easy to adapt the infrastructure to your application’s specific performance, networking, or deployment needs.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|