cdk-nextjs 0.4.1 → 0.4.3

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.
Files changed (47) hide show
  1. package/.jsii +1254 -733
  2. package/API.md +2458 -1108
  3. package/README.md +220 -7
  4. package/docs/1k-concurrent-users-executions.png +0 -0
  5. package/docs/cdk-nextjs-NextjsGlobalContainers.png +0 -0
  6. package/docs/cdk-nextjs-NextjsGlobalFunctions.png +0 -0
  7. package/docs/cdk-nextjs-NextjsRegionalContainers.png +0 -0
  8. package/docs/cdk-nextjs-NextjsRegionalFunctions.png +0 -0
  9. package/docs/cdk-nextjs-cfn-exec-policy.json +27 -0
  10. package/docs/cdk-nextjs.drawio +147 -76
  11. package/docs/usage.xlsx +0 -0
  12. package/lib/constants.d.ts +2 -1
  13. package/lib/constants.js +2 -1
  14. package/lib/generated-structs/OptionalNextjsDistributionProps.d.ts +1 -1
  15. package/lib/generated-structs/OptionalNextjsDistributionProps.js +1 -1
  16. package/lib/index.d.ts +3 -2
  17. package/lib/index.js +8 -2
  18. package/lib/nextjs-api.d.ts +71 -0
  19. package/lib/nextjs-api.js +173 -0
  20. package/lib/nextjs-assets-deployment.js +2 -2
  21. package/lib/nextjs-build/nextjs-build.d.ts +1 -1
  22. package/lib/nextjs-build/nextjs-build.js +2 -2
  23. package/lib/nextjs-compute/nextjs-containers.js +1 -1
  24. package/lib/nextjs-compute/nextjs-functions.d.ts +3 -1
  25. package/lib/nextjs-compute/nextjs-functions.js +11 -10
  26. package/lib/nextjs-distribution.d.ts +3 -3
  27. package/lib/nextjs-distribution.js +3 -3
  28. package/lib/nextjs-file-system.js +1 -1
  29. package/lib/nextjs-post-deploy.js +1 -1
  30. package/lib/nextjs-static-assets.d.ts +0 -4
  31. package/lib/nextjs-static-assets.js +2 -2
  32. package/lib/nextjs-vpc.js +1 -1
  33. package/lib/root-constructs/nextjs-base-construct.d.ts +137 -0
  34. package/lib/root-constructs/nextjs-base-construct.js +112 -0
  35. package/lib/root-constructs/nextjs-global-containers.d.ts +5 -32
  36. package/lib/root-constructs/nextjs-global-containers.js +10 -83
  37. package/lib/root-constructs/nextjs-global-functions.d.ts +5 -32
  38. package/lib/root-constructs/nextjs-global-functions.js +12 -84
  39. package/lib/root-constructs/nextjs-regional-containers.d.ts +5 -21
  40. package/lib/root-constructs/nextjs-regional-containers.js +10 -71
  41. package/lib/root-constructs/nextjs-regional-functions.d.ts +37 -0
  42. package/lib/root-constructs/nextjs-regional-functions.js +58 -0
  43. package/package.json +6 -6
  44. package/lib/root-constructs/nextjs-base-overrides.d.ts +0 -30
  45. package/lib/root-constructs/nextjs-base-overrides.js +0 -3
  46. package/lib/root-constructs/nextjs-base-props.d.ts +0 -64
  47. package/lib/root-constructs/nextjs-base-props.js +0 -3
package/README.md CHANGED
@@ -75,13 +75,13 @@ See [examples/](./examples/) for more usage examples.
75
75
 
76
76
  ### `NextjsGlobalFunctions`
77
77
 
78
- Architecture 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))
78
+ Architecture 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))
79
79
 
80
80
  ![NextjsGlobalFunctions](./docs/cdk-nextjs-NextjsGlobalFunctions.png)
81
81
 
82
82
  ### `NextjsGlobalContainers`
83
83
 
84
- Architecture 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))
84
+ Architecture 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))
85
85
 
86
86
  ![NextjsGlobalContainers](./docs/cdk-nextjs-NextjsGlobalContainers.png)
87
87
 
@@ -91,6 +91,12 @@ Architecture includes [ECS Fargate](https://docs.aws.amazon.com/AmazonECS/latest
91
91
 
92
92
  ![NextjsRegionalContainers](./docs/cdk-nextjs-NextjsRegionalContainers.png)
93
93
 
94
+ ### `NextjsRegionalFunctions`
95
+
96
+ Architecture includes [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) Functions to respond to dynamic requests and [API Gateway REST API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html) to regionally serve requests and distribute static assets. 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-functions.ts))
97
+
98
+ ![NextjsRegionalFunctions](./docs/cdk-nextjs-NextjsRegionalFunctions.png)
99
+
94
100
  ## Why
95
101
 
96
102
  The 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.
@@ -104,9 +110,11 @@ The simplest path to deploy Next.js is on [Vercel](https://vercel.com/) - the Pl
104
110
 
105
111
  ## Limitations
106
112
 
107
- - 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.
113
+ - 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 Distribution 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.
108
114
  - 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).
109
115
  - 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.
116
+ - `NextjsRegionalFunctions` doesn't support streaming because API Gateway doesn't support streaming yet.
117
+ - If using `NextjsRegionalFunctions` without a custom domain, API Gateway REST APIs require a [stage name](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-stages.html) (default: `/prod`) to be specified. This causes links to pages and static assets to break because they're not prefixed with the stage name. You can work around this issue by specifying [basePath](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath) in next.config.js as your stage name. Additionally, you'll need to add middleware logic to rewrite requests to include the stage name because API Gateway does not include the stage name in the path passed to Lambda. See [examples/app-playground/middleware.ts](./examples/app-playground/middleware.ts).
110
118
 
111
119
  ## Additional Security Recommendations
112
120
 
@@ -115,12 +123,203 @@ This construct by default implements all AWS security best practices that a CDK
115
123
  - [VPC Flow Logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html). See [examples/](./examples) for sample implementation.
116
124
  - [Scan ECR Images For Vulnerabilities](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html).
117
125
  - For `NextjsGlobalFunctions` and `NextjsGlobalContainers`, [CloudFront Access Logs](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html). See [examples/](./examples) for sample implementation.
118
- - For `NextjsGlobalContainers` and `NextjsRegionalContainers`, [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)
119
- - 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.
126
+ - For `NextjsGlobalContainers` and `NextjsRegionalContainers`, use [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)
127
+ - If using `NextjsGlobalContainers` and `NextjsRegionalContainers`, 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.
120
128
 
121
129
  ## Estimated Costs
122
130
 
123
- WIP
131
+ ### Assumptions
132
+
133
+ 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.
134
+
135
+ | Metric | Value |
136
+ | ------------------------------------------------------------ | ----- |
137
+ | Monthly Active Users | 1K |
138
+ | Pages Visited Per Month Per User | 100 |
139
+ | Avg Request Size | 50KB |
140
+ | Static Requests Per Page (js, css, etc) | 15 |
141
+ | Static Requests Cache Hit % | 50% |
142
+ | Static Assets Size | 10GB |
143
+ | Dynamic Requests Per Page (document, optimized images, etc.) | 5 |
144
+ | Dynamic Cache Read % | 50% |
145
+ | Dynamic Cache Write % | 5% |
146
+ | Dynamic Cache Data Size | 10GB |
147
+ | Average Dynamic Cache Request Size | 100KB |
148
+
149
+ More Details:
150
+
151
+ - Assume ARM architecture for compute
152
+ - AWS Region: us-east-1
153
+ - Excludes charges related to: CloudWatch Logs, NAT Gateway data processing
154
+
155
+ #### NAT Gateway and Alternatives
156
+
157
+ [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:
158
+
159
+ 1. $0.00 - if you're Next.js app does not need to access the internet, remove the NAT Gateway.
160
+ 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/).
161
+ 3. $32.40 - use 1 AZ instead of 2.
162
+
163
+ ### NextjsGlobalFunctions
164
+
165
+ [AWS Pricing Calculator](https://calculator.aws/#/estimate?id=cbabcb1142ad9b29345b82b33b3cf552eddc966a)
166
+
167
+ | Service | Monthly Usage | Estimated Monthly Cost (USD) |
168
+ | ---------- | ---------------------------------------------- | ---------------------------- |
169
+ | Lambda | 500K requests, 2 GB memory, 150ms avg duration | $0.00 (Always Free Tier) |
170
+ | CloudFront | 2M requests, 100 GB transfer to internet | $0.00 (Always Free Tier) |
171
+ | S3 | 10 GB storage, 750K GET requests | $0.53 |
172
+ | EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $3.90 |
173
+ | VPC | NAT Gateway, 2 AZs | $64.80 |
174
+ | Total | | $69.32 |
175
+
176
+ ### NextjsGlobalContainers
177
+
178
+ [AWS Pricing Calculator](https://calculator.aws/#/estimate?id=1354220e3d611a726139bee4af4277debacd365c)
179
+
180
+ | Service | Monthly Usage | Estimated Monthly Cost (USD) |
181
+ | ----------- | ---------------------------------------------- | ---------------------------- |
182
+ | ECS Fargate | 1 task (1 vCPU, 2 GB) | $28.44 |
183
+ | ALB | 1 LB, 1.04GB/hr, 5.79 conn/sec | $22.50 |
184
+ | CloudFront | 2M requests, 100 GB transfer to internet | $0.00 (Always Free Tier) |
185
+ | S3 | 10 GB storage, 750K GET requests | $0.53 |
186
+ | EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $3.90 |
187
+ | VPC | NAT Gateway, 2 AZs | $64.80 |
188
+ | Total | | $120.53 |
189
+
190
+ ### NextjsRegionalContainers
191
+
192
+ [AWS Pricing Calculator](https://calculator.aws/#/estimate?id=f53440707350f74cf478ca9e45a3ad32f5e16710)
193
+
194
+ | Service | Monthly Usage | Estimated Monthly Cost (USD) |
195
+ | ----------- | ---------------------------------------------- | ---------------------------- |
196
+ | ECS Fargate | 1 task (2 vCPU, 4 GB), always on | $28.44 |
197
+ | ALB | 1 LB, 4.17 GB/hr, 23.15 conn/sec | $40.78 |
198
+ | EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $4.05 |
199
+ | VPC | NAT Gateway, 2 AZs | $64.80 |
200
+ | Total | | $138.07 |
201
+
202
+ ### NextjsRegionalFunctions
203
+
204
+ [AWS Pricing Calculator](https://calculator.aws/#/estimate?id=a6d21afbb983c7efa53da096aa608739da113247)
205
+
206
+ | Service | Monthly Usage | Estimated Monthly Cost (USD) |
207
+ | ----------- | ---------------------------------------------- | ---------------------------- |
208
+ | Lambda | 500K requests, 2 GB memory, 150ms avg duration | $0.00 (Always Free Tier) |
209
+ | API Gateway | 2M requests | $7.00 |
210
+ | EFS | 10 GB storage, 25/2.5 GB Read/Write Throughput | $4.05 |
211
+ | VPC | NAT Gateway, 2 AZs | $64.80 |
212
+ | Total | | $75.85 |
213
+
214
+ ## Performance
215
+
216
+ [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`.
217
+
218
+ ### NextjsGlobalFunctions
219
+
220
+ <details>
221
+ <summary>`NextjsGlobalFunctions` Performance Details</summary>
222
+
223
+ ```bash
224
+ browser.page.TTFB.https://abc123.cloudfront.net/isr:
225
+ min: ......................................................................... 6.3
226
+ max: ......................................................................... 5017.4
227
+ mean: ........................................................................ 11.5
228
+ median: ...................................................................... 10.3
229
+ p95: ......................................................................... 15.6
230
+ p99: ......................................................................... 22.9
231
+ browser.page.TTFB.https://abc123.cloudfront.net/isr/1:
232
+ min: ......................................................................... 3.2
233
+ max: ......................................................................... 560.6
234
+ mean: ........................................................................ 9.4
235
+ median: ...................................................................... 5.4
236
+ p95: ......................................................................... 11.1
237
+ p99: ......................................................................... 162.4
238
+ browser.page.TTFB.https://abc123.cloudfront.net/isr/2:
239
+ min: ......................................................................... 3.1
240
+ max: ......................................................................... 1511.9
241
+ mean: ........................................................................ 9.2
242
+ median: ...................................................................... 5.2
243
+ p95: ......................................................................... 10.7
244
+ p99: ......................................................................... 149.9
245
+ browser.page.TTFB.https://abc123.cloudfront.net/isr/3:
246
+ min: ......................................................................... 3.4
247
+ max: ......................................................................... 131.1
248
+ mean: ........................................................................ 7.1
249
+ median: ...................................................................... 5.3
250
+ p95: ......................................................................... 10.1
251
+ p99: ......................................................................... 64.7
252
+ browser.page.TTFB.https://abc123.cloudfront.net/ssg:
253
+ min: ......................................................................... 6.4
254
+ max: ......................................................................... 5015.1
255
+ mean: ........................................................................ 11.5
256
+ median: ...................................................................... 10.3
257
+ p95: ......................................................................... 15.6
258
+ p99: ......................................................................... 23.3
259
+ browser.page.TTFB.https://abc123.cloudfront.net/ssg/3:
260
+ min: ......................................................................... 2.9
261
+ max: ......................................................................... 98
262
+ mean: ........................................................................ 5.1
263
+ median: ...................................................................... 4.6
264
+ p95: ......................................................................... 8.2
265
+ p99: ......................................................................... 12.8
266
+ browser.page.TTFB.https://abc123.cloudfront.net/ssr:
267
+ min: ......................................................................... 6.4
268
+ max: ......................................................................... 5018.6
269
+ mean: ........................................................................ 11.3
270
+ median: ...................................................................... 10.3
271
+ p95: ......................................................................... 15.6
272
+ p99: ......................................................................... 23.3
273
+ browser.page.TTFB.https://abc123.cloudfront.net/ssr/2:
274
+ min: ......................................................................... 83.4
275
+ max: ......................................................................... 150.7
276
+ mean: ........................................................................ 119
277
+ median: ...................................................................... 111.1
278
+ p95: ......................................................................... 147
279
+ p99: ......................................................................... 147
280
+ browser.page.TTFB.https://abc123.cloudfront.net/streaming:
281
+ min: ......................................................................... 6.4
282
+ max: ......................................................................... 5015.2
283
+ mean: ........................................................................ 11.8
284
+ median: ...................................................................... 10.3
285
+ p95: ......................................................................... 15.6
286
+ p99: ......................................................................... 23.3
287
+ ```
288
+
289
+ </details>
290
+
291
+ ![1K concurrent users](./docs/1k-concurrent-users-executions.png)
292
+
293
+ ### NextjsGlobalContainers
294
+
295
+ <details>
296
+ <summary>`NextjsGlobalContainers` Performance Details</summary>
297
+
298
+ ```bash
299
+ TODO
300
+ ```
301
+
302
+ </details>
303
+
304
+ ### NextjsRegionalContainers
305
+
306
+ <details>
307
+ <summary>`NextjsRegionalContainers` Performance Details</summary>
308
+
309
+ ```bash
310
+ TODO
311
+ ```
312
+
313
+ ### NextjsRegionalFunctions
314
+
315
+ <details>
316
+ <summary>`NextjsRegionalFunctions` Performance Details</summary>
317
+
318
+ ```bash
319
+ TODO
320
+ ```
321
+
322
+ </details>
124
323
 
125
324
  ## Contributing
126
325
 
@@ -140,8 +339,19 @@ A: cdk-nextjs-standalone relies on [OpenNext](https://github.com/sst/open-next).
140
339
  Q: Why not offer API Gateway version of construct?<br/>
141
340
  A: API Gateway does not support streaming.
142
341
 
342
+ Q: How does cdk-nextjs support caching in Next.js?<br/>
343
+ 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
344
+
143
345
  Q: Why EFS instead of S3?<br/>
144
- 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](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.
346
+ 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:
347
+
348
+ | Factor | EFS | S3 |
349
+ | ----------------------------- | ------------------------- | --------------------- |
350
+ | Performance | 1-10ms per file operation | 100-200ms per request |
351
+ | Cold Start Impact | 50-100ms to mount | No impact |
352
+ | Storage Cost | $0.30 / GB-month | $0.023 / GB-month |
353
+ | Read Throughput/Request Cost | $0.03 / GB-month | $0.04 / M requests |
354
+ | Write Throughput/Request Cost | $0.06 / GB-month | $5.00 / M requests |
145
355
 
146
356
  Q: How customizable is the `cdk-nextjs` package for different use cases?<br/>
147
357
  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.
@@ -155,6 +365,9 @@ A: `NextjsGlobalFunctionsProps.overrides.nextjsDistribution` allows you to custo
155
365
  Q: Why use container image for `NextjsGlobalFunctions`?<br />
156
366
  A: Read [The case for containers on Lambda (with benchmarks)](https://aaronstuyvenberg.com/posts/containers-on-lambda).
157
367
 
368
+ Q: How can I `cdk bootstrap --cloudformation-execution-policies ...` my AWS Account with limited permissions for cdk-nextjs to deploy?<br />
369
+ A: See [docs/cdk-nextjs-cfn-exec-policy.json](./docs/cdk-nextjs-cfn-exec-policy.json). Note, this IAM Policy is scoped to all cdk-nextjs constructs so you can remove services if you know the construct you're using doesn't use that service.
370
+
158
371
  ## Acknowledgements
159
372
 
160
373
  This 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).
@@ -0,0 +1,27 @@
1
+ {
2
+ "Version": "2012-10-17",
3
+ "Statement": [
4
+ {
5
+ "Sid": "CfnExecCdkNextjs",
6
+ "Effect": "Allow",
7
+ "Action": [
8
+ "apigateway:*",
9
+ "application-autoscaling:*",
10
+ "cloudformation:*",
11
+ "cloudfront:*",
12
+ "cloudwatch:*",
13
+ "ecs:*",
14
+ "ec2:*",
15
+ "elasticfilesystem:*",
16
+ "elasticloadbalancing:*",
17
+ "iam:*",
18
+ "lambda:*",
19
+ "logs:*",
20
+ "s3:*",
21
+ "servicediscovery:*",
22
+ "ssm:*"
23
+ ],
24
+ "Resource": ["*"]
25
+ }
26
+ ]
27
+ }