cdk-nextjs 0.7.12 → 0.7.14

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 (44) hide show
  1. package/.jsii +346 -100
  2. package/.jsii.tabl.json +1 -1
  3. package/API.md +208 -0
  4. package/README.md +115 -100
  5. package/docs/breaking-changes.md +4 -2
  6. package/docs/development-guide.md +10 -0
  7. package/docs/harness-coverage.md +16 -6
  8. package/docs/next-build-output-guide.md +1 -1
  9. package/lib/adapter/adapter.mjs +4 -1
  10. package/lib/generated-structs/OptionalNextjsApiProps.d.ts +6 -0
  11. package/lib/generated-structs/OptionalNextjsApiProps.js +1 -1
  12. package/lib/generated-structs/OptionalNextjsDistributionProps.d.ts +27 -0
  13. package/lib/generated-structs/OptionalNextjsDistributionProps.js +1 -1
  14. package/lib/nextjs-api.d.ts +11 -0
  15. package/lib/nextjs-api.js +63 -9
  16. package/lib/nextjs-api.test.js +127 -1
  17. package/lib/nextjs-build/nextjs-build.js +1 -1
  18. package/lib/nextjs-cache.js +1 -1
  19. package/lib/nextjs-compute/nextjs-containers.js +1 -1
  20. package/lib/nextjs-compute/nextjs-functions.js +1 -1
  21. package/lib/nextjs-distribution.d.ts +92 -2
  22. package/lib/nextjs-distribution.js +223 -109
  23. package/lib/nextjs-distribution.test.js +492 -12
  24. package/lib/nextjs-post-deploy.js +1 -1
  25. package/lib/nextjs-static-assets.js +1 -1
  26. package/lib/nextjs-static-assets.test.js +19 -7
  27. package/lib/root-constructs/nextjs-base-construct.d.ts +7 -0
  28. package/lib/root-constructs/nextjs-base-construct.js +14 -2
  29. package/lib/root-constructs/nextjs-global-containers.d.ts +16 -1
  30. package/lib/root-constructs/nextjs-global-containers.js +5 -2
  31. package/lib/root-constructs/nextjs-global-functions.d.ts +16 -1
  32. package/lib/root-constructs/nextjs-global-functions.js +5 -2
  33. package/lib/root-constructs/nextjs-regional-containers.js +1 -1
  34. package/lib/root-constructs/nextjs-regional-functions.js +3 -2
  35. package/lib/runtime/lambda.mjs +4 -1
  36. package/lib/runtime/server.mjs +4 -1
  37. package/lib/utils/viewer-request-functions.d.ts +53 -0
  38. package/lib/utils/viewer-request-functions.js +172 -0
  39. package/lib/utils/viewer-request-functions.test.d.ts +1 -0
  40. package/lib/utils/viewer-request-functions.test.js +43 -0
  41. package/package.json +4 -1
  42. package/scripts/e2e-harness/README.md +10 -8
  43. package/scripts/e2e-harness/app.js +7 -2
  44. package/scripts/render-diagrams.mjs +121 -0
package/.jsii CHANGED
@@ -9032,7 +9032,7 @@
9032
9032
  },
9033
9033
  "name": "cdk-nextjs",
9034
9034
  "readme": {
9035
- "markdown": "![Version](https://img.shields.io/github/v/release/cdklabs/cdk-nextjs)\n[![npm version](https://img.shields.io/npm/v/cdk-nextjs.svg?style=flat-square)](https://www.npmjs.org/package/cdk-nextjs)\n![License](https://img.shields.io/github/license/cdklabs/cdk-nextjs)\n\n# CDK Next.js Construct Library\n\n<!--BEGIN STABILITY BANNER-->\n\n---\n\n![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)\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).\n- Choose your AWS architecture for Next.js with the supported constructs: `NextjsGlobalFunctions`, `NextjsGlobalContainers`, `NextjsRegionalContainers`, `NextjsRegionalFunctions`.\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 all constructs (except `NextjsRegionalContainers`) to decrease latency and reduce compute costs by serving directly from S3.\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), [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache) and [`'use cache: remote'`](https://nextjs.org/docs/app/api-reference/directives/use-cache-remote) are shared across compute with [Amazon Simple Storage Service (S3)](https://aws.amazon.com/s3/) with supporting metadata in [Amazon DynamoDB](https://aws.amazon.com/dynamodb), and `revalidateTag`/`revalidatePath` reach plain [`'use cache'`](https://nextjs.org/docs/app/api-reference/directives/use-cache) on every instance. See [`'use cache'` and `'use cache: remote'`](#use-cache-and-use-cache-remote).\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- [Bring Your Own Resources](#bring-your-own-resources) — import existing AWS resources (CloudFront distributions, ECS clusters, ALBs, S3 buckets, DynamoDB tables).\n- [AWS GovCloud (US)](https://aws.amazon.com/govcloud-us) compatible with `NextjsRegionalFunctions` and `NextjsRegionalContainers`.\n\n## Prerequisites\n\n- Next.js app running v16.3 or higher (`next build` fails on older versions). If you don't have one yet - follow [these steps](https://nextjs.org/docs/getting-started) to create one.\n- [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) app either in the same package or separate package. cdk-nextjs supports monorepos.\n- A Docker compatible container engine, but **only** for `NextjsGlobalContainers` and `NextjsRegionalContainers` - we recommend [Rancher Desktop](https://rancherdesktop.io/) with dockerd (moby). The two Functions types deploy zip Lambdas and need no container engine.\n- [Node.js](https://nodejs.org/en) v24 (or LTS)\n\n## Getting Started\n\n1. Install `cdk-nextjs` in the package(s) containing your CDK and Next.js app with `npm i cdk-nextjs`\n2. Deploy your Next.js app to AWS: `cdk deploy`. Make sure you have [AWS credentials](https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html) configured.\n3. Visit URL printed in terminal (CloudFormation Output) to view your Next.js app!\n\nNo `next.config` change is needed: cdk-nextjs runs `next build` itself, and sets [`NEXT_ADAPTER_PATH`](https://nextjs.org/docs/app/api-reference/config/next-config-js/adapterPath) on that build so Next.js loads cdk-nextjs's [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters).\n\n### Registering the adapter yourself\n\nSet `adapterPath` in `next.config` in three cases. An explicit `adapterPath` always wins over `NEXT_ADAPTER_PATH`, so this is also how you pin a specific adapter.\n\n- **cdk-nextjs isn't running your build** — `skipBuild: true`, or you build in CI and hand the output to CDK.\n- **cdk-nextjs isn't a dependency of the Next.js app**, only of the CDK app. cdk-nextjs resolves the adapter from your app's directory, so it can't find it in that layout.\n- **cdk-nextjs is linked from outside your project root** — a `link:`/`file:` dependency on a checkout elsewhere on disk, as this repo's own examples use. The symlink resolves out of the project, and the adapter derives its cache handler path from its own location, so Next.js gets a `cacheHandler` outside `turbopack.root` and Turbopack rejects it. Setting `adapterPath` fixes this because the build resolves it, after whatever put the adapter in place.\n\n```ts\nimport { NextConfig } from \"next\";\n\nconst nextConfig: NextConfig = {\n // ...\n adapterPath: require.resolve(\"cdk-nextjs/adapter\"),\n};\n\nexport default nextConfig;\n```\n\n`require.resolve` works in an ESM `next.config.ts` too, because Next.js transpiles the config to CJS before evaluating it.\n\n### cdk-nextjs Created Dockerfile\n\nFor the Containers types, cdk-nextjs generates a Dockerfile in your Next.js app's directory. It cannot clean the file up after the image is built, so either commit it or gitignore it.\n\nEvery generated Dockerfile starts with the line `# ~~ Generated by cdk-nextjs ~~`, and cdk-nextjs **overwrites** any file carrying it — that way an upgrade that changes how the image is built does not leave a stale Dockerfile behind. To customize it, delete that first line; cdk-nextjs then leaves the file alone. If you edited a generated file without deleting the header, cdk-nextjs saves your version beside it as `<name>.Dockerfile.bak` before replacing it; gitignore that too.\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 WebStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n new NextjsGlobalFunctions(this, \"Nextjs\", {\n buildDirectory: join(import.meta.dirname),\n });\n }\n}\n\nconst app = new App();\n\nnew WebStack(app, \"web-stack\");\n```\n\nSee [examples/](./examples/) for more usage examples.\n\n## Configuration\n\nThe variables below are read at runtime by the cache handler inside your deployed\nLambda functions or containers. Set them on the compute through `overrides`:\n\n```ts\n// NextjsGlobalFunctions / NextjsRegionalFunctions\noverrides: {\n nextjsFunctions: {\n functionProps: { environment: { CDK_NEXTJS_MEMORY_CACHE_TTL_MS: \"0\" } },\n },\n},\n\n// NextjsGlobalContainers / NextjsRegionalContainers\noverrides: {\n nextjsContainers: {\n taskImageOptions: { environment: { CDK_NEXTJS_MEMORY_CACHE_TTL_MS: \"0\" } },\n },\n},\n```\n\nValues you pass are merged over the ones the construct sets, so the same mechanism\noverrides the [infrastructure variables](#infrastructure-configuration) too.\n\n### Cache Configuration\n\n#### `CDK_NEXTJS_MEMORY_CACHE_TTL_MS`\n\nTime to live in milliseconds for in-memory cache entries. After this duration, entries expire and are removed from the cache.\n\n**Note**: Every memory hit is checked against the tag revalidation markers, so an entry revalidated on another instance is not served from memory. A tag's marker is read from DynamoDB only on its first use and a rolling re-read every few minutes; in between, revalidations arrive through the revalidation log (one `Query` per [`CDK_NEXTJS_TAG_REFRESH_MS`](#cdk_nextjs_tag_refresh_ms)). Memory still saves the S3 read and body parse. Set this to `0` to disable the memory cache entirely (all requests will fall through to S3 + DynamoDB).\n\n**Default**: `3600000` (1 hour)\n\n**Examples**:\n\n- Short TTL (5 minutes): `300000` - for frequently changing data\n- Medium TTL (1 hour): `3600000` - balanced between freshness and performance\n- Long TTL (24 hours): `86400000` - for mostly static content\n\n**Trade-offs**:\n\n- Lower values: More cache misses, fresher data, higher S3/DynamoDB costs\n- Higher values: Fewer cache misses, better performance, but longer stale data windows\n\n#### `CDK_NEXTJS_MEMORY_CACHE_MAX_ENTRIES`\n\nMaximum number of cache entries to store in memory. When this limit is reached, the least recently used (LRU) entry is evicted.\n\n**Default**: `1000`\n\n**Examples**:\n\n- Small cache: `100` - minimal memory footprint for simple apps\n- Medium cache: `1000` - good balance for typical applications\n- Large cache: `10000` - for high-traffic apps with many unique pages\n\n**Trade-offs**:\n\n- Lower values: Less memory usage, more cache evictions\n- Higher values: More memory usage, fewer cache evictions, better hit rates\n\n**Memory considerations**: Each entry stores the full cache value (HTML, JSON, etc.). A typical page cache might be 10-100KB, so 1000 entries ≈ 10-100MB of memory. Consider your compute environment's memory limits (Lambda: 128MB-10GB, Fargate: 512MB-30GB) and size accordingly.\n\n### `'use cache'` and `'use cache: remote'`\n\nThe adapter registers two [`cacheHandlers`](https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheHandlers)\nnext to the `cacheHandler` it already sets, unless your `next.config` names a\nhandler of its own for either:\n\n| Directive | `cacheHandlers` name | Stored | Tags |\n| --------------------- | -------------------- | -------------------------------- | ----------------------- |\n| `'use cache'` | `default` | each instance's memory | DynamoDB, all instances |\n| `'use cache: remote'` | `remote` | S3 cache bucket, memory in front | DynamoDB, all instances |\n\n- **`'use cache: remote'`** is shared: an entry any instance generates is the one\n every instance serves, until it expires or a tag is revalidated. Use it for\n results you don't want each Lambda instance or task to compute on its own. It\n costs an S3 `GetObject` the first time an instance reads an entry, and a\n `PutObject` per generated entry. Objects live under\n `<buildId>/_use-cache/` in the cache bucket and are pruned with the build.\n- **`'use cache'`** stays per instance, as Next.js intends — but `revalidateTag`,\n `updateTag` and `revalidatePath` now expire it on every instance, not only the\n one that ran them. Next.js's built-in handler keeps tags in process memory, so\n before this every other instance kept serving the revalidated value, even into\n pages re-rendered because of that revalidation.\n\nBoth read the same per-tag marker rows in the revalidation table that ISR and\nthe data cache use. A tag an instance has not seen yet — an entry read from S3,\na page's implicit `revalidatePath` tags — is read from its marker before it is\ntrusted, once per instance.\n\nAfter that, an instance doesn't re-read the tags it tracks to learn what\nchanged. Each `revalidateTag`/`updateTag` also writes a row to a revalidation\nlog in the same table (`pk = <buildId>#log`, expiring after 15 minutes through\nthe table's `ttl` attribute). At most once per\n[`CDK_NEXTJS_TAG_REFRESH_MS`](#cdk_nextjs_tag_refresh_ms),\neach instance sends one DynamoDB `Query` for the rows written since its last\none and applies those for tags it tracks. So a revalidation on another instance\nis honored within that window (1 second by default), and on the instance that ran\nit immediately. An idle instance's query costs 0.5 RCU a second, where\nre-reading up to 1000 tracked tags cost about 500. Each tag's marker is still\nre-read every 7.5 to 10 minutes, a few each second rather than all at once (about 8\nRCU a second at the most an instance tracks, 10,000 tags). After a gap the log\nmay no longer cover (a Lambda frozen between invocations, a run of failed\nqueries), an instance forgets its tracked markers and reads each again as it's\nneeded. ISR and the data cache share the same copy of the markers, so one\n`revalidateTag` writes each tag's rows once and one `Query` serves them all.\n\nIf you pass your own `revalidationTable`, enabling TTL on its `ttl` attribute is\nrecommended. Without it the log rows (about 100 bytes per revalidated tag) are\nkept until a deploy replaces their build, whose post-deploy step deletes them.\n\nTwo instances that generate the same `'use cache: remote'` entry at the same\nmoment both store it; each serves its own copy until that copy's `revalidate`\ntime, after which S3's is used.\n\n#### `CDK_NEXTJS_TAG_REFRESH_MS`\n\nHow often, at most, in milliseconds, an instance asks the revalidation log what\nother instances revalidated, for `'use cache'`, ISR and the data cache alike. A\n`revalidateTag` elsewhere goes unseen for up to about the window plus a second\n(2 s by default), since `'use cache'` doesn't wait for the answer - and for\nlonger while a query is slow or failing, or for a page render that started\ninside the window, which reads what the instance knew when it began. It's one DynamoDB `Query`,\nhowever many tags the instance tracks, shared by every request on the instance\nduring the window. `0` asks before every cache check, and waits for the answer\n(`'use cache'` only while the instance holds an entry the answer could expire).\nOtherwise `'use cache'` reads don't wait for it, and it applies from the\ninstance's next request. The exception is an instance that hasn't caught up for\nover a second past the window (it sat idle or was frozen): it waits for the\nanswer, before rendering the page for a page request. `'use cache: remote'`\nalways waits.\n\n**Default**: `1000`\n\n#### `CDK_NEXTJS_USE_CACHE_MEMORY_BYTES`\n\nSize bound, in bytes, of each handler's in-memory store: all of `'use cache'`,\nand the memory tier in front of S3 for `'use cache: remote'`. Least recently used\nentries are evicted first.\n\n**Default**: `52428800` (50 MB, Next.js's own default)\n\n### Infrastructure Configuration\n\nThe construct sets these itself and they typically don't need to be modified:\n\n#### `CDK_NEXTJS_BUILD_ID`\n\nUnique identifier for the Next.js build. Used for cache isolation between deployments.\n\n#### `CDK_NEXTJS_CACHE_BUCKET_NAME`\n\nS3 bucket name for storing cached data (optimized images, data cache, full route cache, `'use cache: remote'`).\n\n#### `CDK_NEXTJS_REVALIDATION_TABLE_NAME`\n\nDynamoDB table name for tracking cache revalidations and tag-to-cache-key mappings.\n\n#### `DEBUG`\n\nNot set by default. Set it to `cdk-nextjs:*` to enable debug logs. This is especially useful to see cache handler activity.\n\n### `next.config.js` options cdk-nextjs reads\n\nBoth are read out of your build, so you set them in one place — your app — and the\ninfrastructure follows.\n\n#### `basePath`\n\nBecomes the S3 key prefix for static assets and the prefix on every CloudFront\ncache behavior. See [Resource Isolation](#resource-isolation); the `basePath`\nprop only exists to be explicit about it.\n\n#### `assetPrefix`\n\n- **A path** (`assetPrefix: \"/cdn\"`) — Next.js emits bundle URLs as\n `/cdn/_next/static/...`, on top of `basePath` rather than under it, while the\n objects stay in S3 under `<basePath>/_next/static/...`. `NextjsGlobalFunctions`\n and `NextjsGlobalContainers` add a cache behavior for\n `<assetPrefix>/_next/static*` pointing at the assets bucket, with a CloudFront\n Function that rewrites the prefix back to the S3 keys. It costs one of the 25\n cache behaviors cdk-nextjs budgets for you. **Not supported on\n `NextjsRegionalFunctions` or `NextjsRegionalContainers`** — nothing there maps\n the prefix back, so bundles would 404; synth warns if your app sets one.\n- **An absolute URL** (`assetPrefix: \"https://cdn.example.com\"`) — names an origin\n cdk-nextjs doesn't serve, so nothing is added, on any construct. Point that host\n at the assets bucket yourself, including the `basePath` prefix the objects are\n stored under.\n- **An absolute URL with a path** (`assetPrefix: \"https://cdn.example.com/cdn\"`) —\n its path is treated exactly like the path case above, because `next build`\n compiles a `/cdn/_next/:path+` rewrite of its own: `next start` serves bundles\n under that path too, so the Global constructs answer there as well. Useful when\n that host is a second domain on the same distribution.\n\n## Splitting a Large App Across Functions\n\nOnly for `NextjsGlobalFunctions` and `NextjsRegionalFunctions`, and only if you\nneed it. AWS Lambda caps a function's unzipped code at 250 MB. If your app\nexceeds it, cdk-nextjs fails at synth with the measured size and points you here:\n\n```\nFunction group \"default\" is 274 MB unzipped, over Lambda's 250 MB limit. Use the\n`functionGroups` prop to package routes into separate functions. Note that\nsplitting only removes route-local code — anything reachable from a shared layout\nor the `next` runtime is in every group.\n```\n\n`functionGroups` declares which routes get their own Lambda. Everything you do\nnot name stays on the `default` function:\n\n```ts\nnew NextjsGlobalFunctions(this, \"Nextjs\", {\n buildDirectory: join(import.meta.dirname, \"..\", \"web\"),\n functionGroups: [\n { name: \"reports\", routes: [\"/dashboard/reports/**\"] },\n { name: \"admin\", routes: [\"/admin\", \"/admin/**\", \"/settings\"] },\n ],\n});\n```\n\nEach group becomes one Lambda function containing only the routes it owns (plus\nthe framework closure every function needs), and one CloudFront behavior — or API\nGateway resource, for `NextjsRegionalFunctions` — per pattern.\n\n**Route patterns** are either an exact path (`/settings`) or a subtree\n(`/admin/**`). A subtree owns what is _under_ it, not the path itself:\n`/admin/**` does not claim `/admin`. To own a page and everything under it, list\nboth, as the example above does: `[\"/admin\", \"/admin/**\"]`. Where two groups\ncould both match, the longest pattern wins, so `/api/**` and `/api/reports/**`\ncan coexist in different groups. Dynamic segments (`/blog/[slug]`), route group\nsegments (`/(marketing)/about`), `/`, and `/**` are rejected at synth —\nCloudFront matches literal path prefixes and cannot express them. `/index` is\naccepted for an App Router `app/index/page.tsx`, but not for a Pages Router home\npage, which is the same file as `/`.\n\n**What is routed for you.** Patterns decide which _files_ a group packages; the\nedge then has to send every URL those files serve to that group. cdk-nextjs\nderives these without extra patterns:\n\n- A Pages Router page's data URL, `/_next/data/<buildId>/<page>.json`. The\n behavior carries the literal build ID, so it changes on every deploy; a\n client still on the previous build falls through to the `default` function,\n which answers 404, and the Next.js client reloads the page.\n- The `trailingSlash` form of an exact pattern (`/pricing/`). CloudFront gets a\n behavior for it; on `NextjsRegionalFunctions` none is needed, because API\n Gateway already routes `/pricing/` to the `/pricing` resource.\n- The parent of an optional catch-all. `/shop/**` moving\n `app/shop/[[...slug]]/page.tsx` also routes `/shop`, which the same file\n serves. Do not add `/shop` yourself: it matches no route and is rejected.\n- An [interception route](https://nextjs.org/docs/app/api-reference/file-conventions/intercepting-routes)\n is packaged with the group that owns the URL it intercepts, not by its own\n path: `app/feed/(..)photo/[id]` follows `/photo/[id]`, because a soft\n navigation requests `/photo/1` and Next.js rewrites it in whichever function\n receives it.\n\n**What synth rejects.** After assigning routes, cdk-nextjs replays the\nCloudFront behaviors over every URL each file serves and fails when one would\nreach a function without its file, naming the file, the URL and the pattern to\nadd. That covers:\n\n- A file behind several templates that a pattern only partly covers — root\n params (`app/[locale]/page.tsx` prerendered as `/en` and `/de`) grouped with\n `/en` alone. A dynamic first segment can never be routed, so such a file stays\n in `default`.\n- An intercepted URL space split between groups (`/photo/[id]` in one,\n `/photo/1` in another), since the intercepting file cannot be in both.\n- A `next.config` rewrite whose source reaches one group and whose destination\n file is in another: rewrites run inside the function that received the\n request. Only rewrites with a literal destination are checked.\n- A group pattern that duplicates a top-level `public/` entry's behavior\n (`public/docs/` and `/docs/**`), or sits under one (`/docs/guide/**`), which\n would send the group's routes to S3.\n\nNot checked, because it is only known at request time: **a middleware\n`NextResponse.rewrite()`** to a route in another group reaches the function that\nreceived the original URL, which lacks the route's file. It answers 404 (or a\n308 to the canonical URL when only the case differs) and logs a warning naming\nthe group that owns the route. Keep a middleware rewrite's source and\ndestination in the same group. The same goes\nfor a `next.config` rewrite whose destination is built from its parameters\n(`/b/:slug` → `/blog/:slug`), and for a dynamic segment of a `default` route\nthat overlaps a group's literal path (`/[section]/intro` against `/docs/**`).\nLikewise **a Pages Router `res.revalidate()`** renders the page in the function\nthat called it, so it can only revalidate pages in its own group; the error\nnames the group that owns the page. Use `revalidatePath()` or `revalidateTag()`\nacross groups. And **an `<Image>` whose `src` is a route in another group**\n(`/api/avatar/42` under an `/api/**` group) can't be optimized: `/_next/image`\nruns in the `default` function, which fetches a local source that isn't a\n`public/` or `_next/static` file by running its route in-process, and it doesn't\ncarry that route, so the image request fails. Keep image-serving routes in\n`default`, or point `src` at a `public/` file or a remote URL.\n\n**What splitting does and does not save.** Every function ships the same `next`\nruntime closure, so splitting only moves route-_local_ code and its dependencies.\nA group whose routes import a large library is worth extracting; splitting an app\nin half does not halve either function.\n\nNotes:\n\n- Group names must be valid CDK construct ids (letters, digits, `-`). `default`\n is reserved.\n- A pattern that matches no route in the build is a synth error, not a silent\n no-op — it is almost always a typo.\n- Cannot be combined with `i18n`: locale-prefixed routes would need one\n CloudFront behavior per locale per pattern.\n- Group patterns (and the routes derived from them above) count against the\n same CloudFront behavior budget as your `public/` entries (see\n [Limitations](#limitations)).\n- Per-group `overrides` let you size each function independently:\n `{ name: \"reports\", routes: [...], overrides: { functionProps: { memorySize: 2048 } } }`.\n\n## Architecture\n\nHow requests are served inside the compute — the adapter runtime, and where it deliberately differs from `next start` — is in [docs/adapter-runtime.md](./docs/adapter-runtime.md).\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))\n\n```mermaid\narchitecture-beta\n group aws(cloud)[AWS Cloud]\n group cache[Cache Layer] in aws\n\n service user(internet)[User]\n service cloudfront(server)[CloudFront Distribution] in aws\n service s3static(disk)[S3 Static Assets] in aws\n service lambda(server)[Lambda Function] in aws\n service dynamodb(database)[DynamoDB Table] in cache\n service s3cache(disk)[S3 Cache Bucket] in cache\n\n user:R --> L:cloudfront\n cloudfront:R --> L:s3static\n cloudfront:R --> L:lambda\n lambda:R --> L:dynamodb\n lambda:R --> L:s3cache\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))\n\n```mermaid\narchitecture-beta\n group aws(cloud)[AWS Cloud]\n group vpc[VPC] in aws\n group cache[Cache Layer] in aws\n\n service user(internet)[User]\n service cloudfront(server)[CloudFront Distribution] in aws\n service s3static(disk)[S3 Static Assets] in aws\n service alb(server)[Application Load Balancer] in vpc\n service fargate(server)[ECS Fargate Containers] in vpc\n service dynamodb(database)[DynamoDB Table] in cache\n service s3cache(disk)[S3 Cache Bucket] in cache\n\n user:R --> L:cloudfront\n cloudfront:R --> L:s3static\n cloudfront:R --> L:alb\n alb:R --> L:fargate\n fargate:R --> L:dynamodb\n fargate:R --> L:s3cache\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```mermaid\narchitecture-beta\n group aws(cloud)[AWS Cloud]\n group vpc[VPC] in aws\n group cache[Cache Layer] in aws\n\n service user(internet)[User]\n service alb(server)[Application Load Balancer] in vpc\n service fargate(server)[ECS Fargate Containers] in vpc\n service dynamodb(database)[DynamoDB Table] in cache\n service s3cache(disk)[S3 Cache Bucket] in cache\n\n user:R --> L:alb\n alb:R --> L:fargate\n fargate:R --> L:dynamodb\n fargate:R --> L:s3cache\n```\n\n### `NextjsRegionalFunctions`\n\nArchitecture 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))\n\n```mermaid\narchitecture-beta\n group aws(cloud)[AWS Cloud]\n group cache[Cache Layer] in aws\n\n service user(internet)[User]\n service apigateway(server)[API Gateway REST API] in aws\n service s3static(disk)[S3 Static Assets] in aws\n service lambda(server)[Lambda Function] in aws\n service dynamodb(database)[DynamoDB Table] in cache\n service s3cache(disk)[S3 Cache Bucket] in cache\n\n user:R --> L:apigateway\n apigateway:R --> L:s3static\n apigateway:R --> L:lambda\n lambda:R --> L:dynamodb\n lambda:R --> L:s3cache\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- Integrate through Next.js's official interfaces. Build on the [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters) API and [`@next/routing`](https://www.npmjs.com/package/@next/routing) rather than Next.js internals, so new Next.js versions rarely break this construct. Where no public interface exists yet, the dependency is listed in [Next.js private APIs](docs/nextjs-private-apis.md).\n- Security first.\n- One architecture does not fit all.\n- Enable customization everywhere.\n\n## Bring Your Own Resources\n\ncdk-nextjs supports importing existing AWS resources instead of creating new ones. This is especially useful for per-branch (MR/PR) environments where you deploy shared infrastructure (VPC, ECS cluster, ALB) once and spin up lightweight branch stacks that reuse it.\n\n### Supported Resources\n\n| Resource | Prop | Available On |\n| --------------------------- | -------------------- | ---------------------------------------------------- |\n| S3 Cache Bucket | `cacheBucket` | All constructs |\n| DynamoDB Revalidation Table | `revalidationTable` | All constructs |\n| S3 Static Assets Bucket | `staticAssetsBucket` | All constructs |\n| CloudFront Distribution | `distribution` | `NextjsGlobalFunctions`, `NextjsGlobalContainers` |\n| ECS Cluster | `ecsCluster` | `NextjsGlobalContainers`, `NextjsRegionalContainers` |\n| ALB | `alb` | `NextjsGlobalContainers`, `NextjsRegionalContainers` |\n\n### Resource Isolation\n\n- **Cache bucket and DynamoDB table** must be dedicated to one deployment. Sharing either between deployments (branches, stages, apps) is not supported: each deploy's post-deploy step prunes every cache object and revalidation entry that isn't from its own current build, so deploying one branch wipes the others' caches. Buckets and tables are cheap, so give each deployment its own, or leave `cacheBucket`/`revalidationTable` unset and let cdk-nextjs create them (they are removed with the stack).\n- **Static assets bucket** can be shared, but only between deployments with different `basePath`s, which become their S3 key prefixes. Pruning only looks at `<basePath>/_next/`, so it never touches another prefix. Two deployments under the same prefix (for example two subdomain previews both at the root) overwrite each other's `public/` files and prune each other's `_next/` assets once they are past the prune TTL (30 days by default), so give those their own buckets. `NextjsGlobalFunctions` and `NextjsGlobalContainers` read the `basePath` out of your Next.js build and use it as the S3 key prefix, since CloudFront serves assets from S3 by request path and the two can't differ. Set the `basePath` prop only if you want to be explicit about it; a value that disagrees with your app's fails at synth. Each deployment also adds an ownership tag per static asset upload (1 to 3, by whether the build has `public/` files and service workers) to a bucket created in your CDK app; an imported bucket gets none. S3 allows 50 tags per bucket, so such a bucket holds at least 16 deployments.\n\n### Shared ALB and `removeAutoCreatedListener()`\n\n`ApplicationLoadBalancedFargateService` always creates a listener on port 80 — there is no opt-out. When you import an ALB that already has a listener on that port, the duplicate causes a deployment failure. Since CDK doesn't expose a way to prevent this, `removeAutoCreatedListener()` surgically removes the generated CloudFormation resources: the `CfnListener`, its security group ingress rule, rebuilds the ECS service `DependsOn` without the deleted listener, and removes auto-created `CfnOutput` resources:\n\n```ts\nconst nextjs = new NextjsRegionalContainers(this, \"Nextjs\", {\n // ...\n alb: sharedAlb,\n ecsCluster: sharedCluster,\n});\nnextjs.nextjsContainers.removeAutoCreatedListener();\n```\n\n### Examples\n\nSee [examples/bring-your-own/](./examples/bring-your-own/) for a complete deployable example with a shared VPC, ECS cluster, and ALB, per-branch host-header routing, and a cache bucket, revalidation table, and static assets bucket per branch.\n\n## Preview Environments (Per-Branch Deployments)\n\ncdk-nextjs can deploy ephemeral preview environments per merge request (MR) or pull request (PR). The recommended approach uses subdomain-based routing (`pr-123.app.example.com`) so each preview environment runs the same Next.js build as production — no `basePath` configuration or separate builds required.\n\nSee [examples/bring-your-own/](./examples/bring-your-own/) for a fully deployable example using `NextjsRegionalContainers` with a shared VPC, ALB, and ECS Cluster (connected via SSM Parameter Store), and S3 buckets and a DynamoDB table owned by each branch stack.\n\nEach preview environment needs its own cache bucket and revalidation table (see [Resource Isolation](#resource-isolation)). Since every preview serves the same build at the root, give each its own static assets bucket too. Leaving `cacheBucket`, `revalidationTable`, and `staticAssetsBucket` unset does this: cdk-nextjs creates them in the branch stack and deletes them when it's torn down.\n\n### Prerequisites\n\n- Wildcard DNS record: `*.app.example.com` → your routing layer (ALB, CloudFront, API Gateway)\n- Wildcard ACM certificate: `*.app.example.com`\n\n### Per-Architecture Recommendations\n\n#### `NextjsGlobalContainers` and `NextjsRegionalContainers` (ALB-based)\n\nSubdomain routing via ALB host-based listener rules. This is the fastest and simplest approach. For `NextjsGlobalContainers`, CloudFront forwards the `Host` header to the ALB origin, so the ALB handles all branch routing — no CloudFront changes needed per branch.\n\nSee [examples/bring-your-own/](./examples/bring-your-own/) for the full implementation.\n\n#### `NextjsRegionalFunctions` (API Gateway)\n\nSubdomain routing via API Gateway custom domain mappings.\n\n1. Per branch, deploy a cdk-nextjs stack that creates its own API Gateway, Lambda function, S3 buckets, and DynamoDB table\n2. Create an API Gateway custom domain (`pr-123.app.example.com`) mapped to the branch's API stage\n3. Tear down the branch stack on MR close\n\n#### `NextjsGlobalFunctions` (Lambda + CloudFront)\n\nRequires a separate cdk-nextjs stack per branch, each with its own CloudFront distribution. CloudFront cannot route to different Lambda Function URL origins based on the `Host` header — origin selection is determined by cache behavior path patterns, not request headers.\n\n1. Per branch, deploy a full cdk-nextjs stack that creates its own CloudFront distribution, Lambda function, S3 buckets, and DynamoDB table\n2. Point `pr-123.app.example.com` DNS to the branch's CloudFront distribution\n3. Tear down the branch stack on MR close\n\nNote: CloudFront distributions take several minutes to create/update, so this architecture has the slowest preview environment spin-up time.\n\n## Limitations\n\n- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers` (which use CloudFront), each top level file/directory in `public/` takes a CloudFront cache behavior, and a distribution's default quota is 75 behaviors (cdk-nextjs uses 3 to 6 itself). 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. If you raise the quota for your account, set `maxCacheBehaviors` on the distribution props (`overrides.nextjsGlobalFunctions.nextjsDistributionProps`, or the Containers equivalent) to match. The synth check only counts the behaviors cdk-nextjs adds, so if you pass your own `distribution` (or add behaviors through `overrides.nextjsDistribution.distributionProps`), lower `maxCacheBehaviors` by the behaviors it already has. See [CloudFront Quotas](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html) for more information.\n- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers`, on-demand revalidation ([revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath), [revalidateTag](https://nextjs.org/docs/app/api-reference/functions/revalidateTag)) creates the CloudFront invalidations for you (so does the Pages Router's `res.revalidate()`, for the page's HTML and `_next/data` copies), but [invalidations](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html) are eventually consistent: until one completes (usually seconds, occasionally minutes), some edge locations can still serve the previous copy.\n - **Burst limit.** CloudFront allows 15 wildcard invalidation paths in progress per distribution, and each page cdk-nextjs invalidates is one wildcard path (`/blog*`). Next.js sends every `revalidatePath`/`revalidateTag` from one request as a single call, one invalidation per cache-life profile, however many pages it covers. A Pages Router `res.revalidate()` sends one invalidation per call, and a page regenerated after a stale-while-revalidate `revalidateTag(tag, profile)` sends one more when it lands. When the quota is full, cdk-nextjs retries the request as a single `/*` (a colder edge, never a stale page). If that is also rejected, it logs `Failed to create CloudFront invalidation` and the page stays stale at the edge until its `s-maxage` expires.\n - **For bulk updates** (a CMS webhook touching many pages), call `revalidateTag` with a tag the pages share, or `revalidatePath` for each page within one request, rather than looping `res.revalidate()`. If you need to know when invalidations are dropped, add a CloudWatch Logs metric filter on that log line.\n- If using `NextjsGlobalFunctions`, a client-supplied `Authorization` header does not reach your app: CloudFront signs each request to the Lambda Function URL with SigV4, which uses that header. Send credentials under a different name (e.g. `x-authorization`) and read that header in your app. cdk-nextjs does not rename it for you — it no longer uses [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter), so `AWS_LWA_AUTHORIZATION_SOURCE` no longer applies.\n- If using `NextjsGlobalFunctions`, a `POST` or `PUT` with a request body must carry an `x-amz-content-sha256` header holding the hex SHA-256 of that body. This is [AWS behavior](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-lambda.html), not a cdk-nextjs choice: CloudFront signs the origin request to the Lambda Function URL with SigV4 but does not hash the body, and Lambda rejects an unsigned payload with `403 InvalidSignatureException`. Requests from your own pages are handled for you — cdk-nextjs injects a `fetch`/`XMLHttpRequest` wrapper into the client bundle that adds the header, so server actions, route handlers, `fetch` and `XMLHttpRequest` from the browser work untouched, whatever the body type. The exception is a native `<form method=\"post\">` submitted before the page hydrates (a server action form without JavaScript, or clicked before the bundle loads): the browser sends it, not the wrapper, so it has no header and gets the 403. **Anything that is not that browser bundle has to add the header itself**: `curl`, a mobile app, a webhook provider, another service calling your API routes. Server-to-server callers can compute it with the AWS SDK's `Sha256`, or with `crypto.createHash(\"sha256\").update(body).digest(\"hex\")`. The other three deployment types are unaffected.\n- If using `NextjsGlobalFunctions`, a `HEAD` request is answered with `content-length: 0`, whatever length your handler declares. This is Lambda Function URL behavior: the same runtime's declared length reaches the client through API Gateway (`NextjsRegionalFunctions`) and from an ALB, with or without CloudFront in front (the two Containers types).\n- Group patterns declared via [`functionGroups`](#splitting-a-large-app-across-functions) also count against the CloudFront behavior limit above.\n- 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 — leave the construct's `basePath` prop unset when you do, since API Gateway strips the stage before matching resources. API Gateway strips the stage from the path it passes to Lambda; cdk-nextjs puts it back for an app whose `basePath` starts with it, reading the stage off each request, so no middleware is needed and a renamed stage needs no configuration. Mapping a custom domain at the root avoids all of this — see [examples/regional-functions/README.md](./examples/regional-functions/README.md#with-a-custom-domain-no-stage-workarounds).\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`, use [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)\n- 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.\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| Dynamic Revalidate Tag % | 1% |\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### NextjsGlobalFunctions\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=23611f6fea87ef05d5fe87c33135ddde43b17a98)\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 | 20 GB storage, 1M GET, 250K PUT requests | $2.11 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| Total | | $8.09 |\n\n### NextjsGlobalContainers\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=02f0073e612d1eee2a7ccace2c636adc5f0acab7)\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 | 20 GB storage, 1M GET, 250K PUT requests | $2.11 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| VPC | NAT Gateway, 2 AZs | $65.70 |\n| Total | | $121.25 |\n\n### NextjsRegionalContainers\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=e214abe60eb4e24fc5866d07ef4355393261af3c)\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| S3 | 10 GB storage, 250K GET, 250K PUT requests | $1.58 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| VPC | NAT Gateway, 2 AZs | $65.70 |\n| Total | | $139.00 |\n\n### NextjsRegionalFunctions\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=60da38c7993c1baeee2fee4bd19ba6441608bb15)\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| API Gateway | 2M requests | $7.00 |\n| S3 | 10 GB storage, 250K GET, 250K PUT requests | $1.58 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| Total | | $11.08 |\n\n## Performance\n\nMeasured with [k6](https://grafana.com/docs/k6/latest/) from EC2 in us-east-1, the region of the stacks under test (one load generator per stack), against a small benchmark app ([`examples/bench-app`](./examples/bench-app)) that makes no calls outside its own stack. Functions run the default 2048 MB Lambda functions. Containers run the default 1 vCPU / 2 GB Fargate tasks, with CPU autoscaling from 2 to 10 tasks added (the default is one task and no autoscaling). Methodology, caveats, and how to reproduce the numbers: [`examples/load-tests`](./examples/load-tests).\n\nWhat each route measures:\n\n- `static-asset`, `static`, `image`: CloudFront's cache on the Global constructs, and the construct itself on the Regional ones.\n- `isr`: the cache until the page is stale (10 s), then a background revalidation through the S3 + DynamoDB cache.\n- `ssr`, `stream`, `rsc`, `api`: the construct's compute on every request, on every construct.\n\n<!-- tables generated by `pnpm report` in examples/load-tests -->\n\n| Construct | `ssr` at 10 req/s | `ssr` at 50 req/s | `ssr` capacity | `isr` capacity | Cold start p50 |\n| -------------------------- | ----------------- | ----------------------------------------- | -------------- | -------------- | -------------- |\n| `NextjsGlobalFunctions` | 36 / 103 | 33 / 84 | ≥ 6560 req/s | ≥ 6560 req/s | 1390 ms |\n| `NextjsGlobalContainers` | 19 / 44 | 18 / 219 | 194 req/s | ≥ 6400 req/s | – |\n| `NextjsRegionalContainers` | 22 / 172 | 1972 / 39536 ⚠️ 0.54% errors, 76% dropped | 675 req/s | ≥ 6075 req/s | – |\n| `NextjsRegionalFunctions` | 32 / 114 | 30 / 103 | ≥ 6560 req/s | ≥ 6560 req/s | 1380 ms |\n\n_Latency is p50 / p99 in ms, with every route loaded at that rate at once. Capacity is the highest rate sustained with p99 under 1000 ms and under 1% errors._\n\nWhat this means for choosing one:\n\n- **Functions constructs scale with no sizing.** Both held at least 6,560 req/s of SSR, the load generator's limit, at the same latency as at 10 req/s. The cost is a cold start of about 1.4 s on a new execution environment.\n- **Containers constructs are fastest per request but need sizing.** Two 1 vCPU tasks served SSR at 19–22 ms p50 against Lambda's ~30 ms, but tasks take minutes to add. Past capacity they don't degrade gradually: tasks too busy to answer the ALB health check are replaced, which leaves fewer tasks for the same load. Leave headroom.\n- **CloudFront carries the Global constructs' cached traffic.** Prerendered pages, ISR hits, images and assets were answered at the edge in 2–3 ms at every rate. On the Regional constructs every request reaches the construct: `NextjsRegionalContainers` serves assets and image optimization from the same tasks, so 50 req/s on every route at once (400 req/s) is already more than two tasks handle.\n- **Cached pages scale on every construct.** ISR hits held at least 6,000 req/s on all four: at the edge on the Global constructs, and through the S3 + DynamoDB cache on the Regional ones, where each instance holds a tag's revalidation marker for a second (`CDK_NEXTJS_TAG_REFRESH_MS`, see the [Caching Guide](./docs/caching-guide.md)).\n\n<details>\n<summary><code>NextjsGlobalFunctions</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | 250 req/s | 1000 req/s | CDN hits |\n| ------------- | --------- | --------- | --------- | ---------- | -------- |\n| static-asset | 2.1 / 4.8 | 2.1 / 4.7 | 2.0 / 4.9 | 2.1 / 11 | 100% |\n| static | 3.3 / 7.5 | 3.2 / 6.8 | 3.1 / 7.3 | 3.2 / 13 | 100% |\n| isr | 3.3 / 7.4 | 3.3 / 7.7 | 3.2 / 7.2 | 3.2 / 12 | 100% |\n| ssr | 36 / 103 | 33 / 84 | 31 / 86 | 29 / 73 | 0% |\n| stream | 233 / 268 | 230 / 261 | 228 / 259 | 226 / 252 | 0% |\n| stream (TTFB) | 32 / 89 | 29 / 66 | 27 / 65 | 25 / 57 | |\n| rsc | 32 / 67 | 28 / 61 | 27 / 60 | 25 / 52 | 0% |\n| api | 29 / 79 | 26 / 55 | 24 / 61 | 23 / 47 | 0% |\n| image | 3.2 / 6.3 | 3.1 / 6.8 | 3.1 / 7.0 | 3.1 / 12 | 100% |\n\nCapacity: `isr` ≥ 6560 req/s, `ssr` ≥ 6560 req/s.\n\nCold start, time to first byte of `/ssr` on a new execution environment: p50 1390 ms, p90 1451 ms (warm: 84 ms).\n\nBrowser, p75 in ms, under 50 req/s per route:\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | --- | ---- | ---------------------- |\n| static | 76 | 13 | 15 |\n| ssr | 80 | 39 | 53 |\n| isr | 52 | 8.7 | 12 |\n| stream | 64 | 34 | 38 |\n| image | 52 | 6.7 | 10 |\n\n</details>\n\n<details>\n<summary><code>NextjsGlobalContainers</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | CDN hits |\n| ------------- | --------- | --------- | -------- |\n| static-asset | 1.4 / 3.9 | 1.5 / 3.7 | 100% |\n| static | 1.9 / 4.8 | 1.8 / 3.7 | 100% |\n| isr | 2.0 / 4.4 | 1.7 / 4.0 | 100% |\n| ssr | 19 / 44 | 18 / 219 | 0% |\n| stream | 217 / 242 | 217 / 359 | 0% |\n| stream (TTFB) | 17 / 45 | 16 / 207 | |\n| rsc | 12 / 26 | 12 / 86 | 0% |\n| api | 11 / 23 | 10 / 81 | 0% |\n| image | 2.0 / 4.7 | 1.7 / 4.1 | 100% |\n\nCapacity: `isr` ≥ 6400 req/s, `ssr` 194 req/s.\n\nBrowser, p75 in ms, under 50 req/s per route:\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | --- | ---- | ---------------------- |\n| static | 88 | 12 | 17 |\n| ssr | 80 | 26 | 39 |\n| isr | 56 | 6.1 | 13 |\n| stream | 64 | 20 | 25 |\n| image | 52 | 5.4 | 11 |\n\n</details>\n\n<details>\n<summary><code>NextjsRegionalContainers</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | CDN hits |\n| ------------- | --------- | ----------------------------------------- | -------- |\n| static-asset | 18 / 159 | 1698 / 28824 ⚠️ 0.40% errors, 72% dropped | no CDN |\n| static | 41 / 163 | 916 / 28298 ⚠️ 0.46% errors, 66% dropped | no CDN |\n| isr | 40 / 169 | 697 / 27146 ⚠️ 0.36% errors, 57% dropped | no CDN |\n| ssr | 22 / 172 | 1972 / 39536 ⚠️ 0.54% errors, 76% dropped | no CDN |\n| stream | 221 / 354 | 1909 / 27423 ⚠️ 0.44% errors, 72% dropped | no CDN |\n| stream (TTFB) | 19 / 166 | 1881 / 27162 | |\n| rsc | 9.4 / 64 | 433 / 26066 ⚠️ 0.25% errors, 39% dropped | no CDN |\n| api | 6.9 / 55 | 429 / 26041 ⚠️ 0.25% errors, 38% dropped | no CDN |\n| image | 140 / 440 | 1599 / 27489 ⚠️ 0.22% errors, 69% dropped | no CDN |\n\nCapacity: `isr` ≥ 6075 req/s, `ssr` 675 req/s.\n\nBrowser, p75 in ms, under 10 req/s per route. `static` is each visit's first page: on a plain-HTTP origin, Chrome tries HTTPS first and falls back after about 3 s (HTTPS-Upgrades), which real visitors pay too. Put a certificate on the ALB to avoid it.\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | ---- | ---- | ---------------------- |\n| static | 3100 | 3047 | 16 |\n| ssr | 68 | 14 | 27 |\n| isr | 88 | 43 | 13 |\n| stream | 48 | 11 | 13 |\n| image | 212 | 38 | 9.6 |\n\n</details>\n\n<details>\n<summary><code>NextjsRegionalFunctions</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | 250 req/s | 1000 req/s | CDN hits |\n| ------------- | --------- | --------- | --------- | ---------- | -------- |\n| static-asset | 34 / 76 | 32 / 72 | 30 / 72 | 30 / 68 | no CDN |\n| static | 58 / 138 | 57 / 140 | 57 / 147 | 57 / 127 | no CDN |\n| isr | 58 / 149 | 56 / 124 | 56 / 145 | 55 / 125 | no CDN |\n| ssr | 32 / 114 | 30 / 103 | 29 / 115 | 29 / 98 | no CDN |\n| stream | 229 / 293 | 227 / 288 | 227 / 299 | 226 / 282 | no CDN |\n| stream (TTFB) | 27 / 85 | 25 / 84 | 25 / 97 | 24 / 76 | |\n| rsc | 27 / 76 | 26 / 73 | 25 / 83 | 25 / 70 | no CDN |\n| api | 24 / 84 | 22 / 70 | 22 / 97 | 22 / 67 | no CDN |\n| image | 127 / 210 | 125 / 221 | 125 / 236 | 123 / 211 | no CDN |\n\nCapacity: `isr` ≥ 6560 req/s, `ssr` ≥ 6560 req/s.\n\nCold start, time to first byte of `/ssr` on a new execution environment: p50 1380 ms, p90 1442 ms (warm: 71 ms).\n\nBrowser, p75 in ms, under 50 req/s per route:\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | --- | ---- | ---------------------- |\n| static | 128 | 70 | 17 |\n| ssr | 88 | 35 | 50 |\n| isr | 108 | 62 | 13 |\n| stream | 64 | 31 | 36 |\n| image | 220 | 60 | 9.6 |\n\n</details>\n\n## Guides\n\n- [Caching Guide](./docs/caching-guide.md)\n- [Pruning Guide](./docs/pruning-guide.md)\n- [Native Dependencies Guide](./docs/native-dependencies-guide.md)\n- [Next Build Output Guide](./docs/next-build-output-guide.ts)\n- [Development Guide](./docs/development-guide.ts)\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) or [OpenNext](https://opennext.js.org)?<br/>\nA: cdk-nextjs builds on Next.js's official [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters) API and runs requests through [`@next/routing`](https://www.npmjs.com/package/@next/routing), the routing library Next.js publishes for platform adapters. Next.js tells cdk-nextjs what it built, and routing follows the same rules as `next start`. Nothing re-implements Next.js's router or patches its server. The few Next.js internals cdk-nextjs does load (the image optimizer and static file server) are loaded as they are, not modified. This keeps upgrades cheap and breaking changes rare. cdk-nextjs is tested against Next.js's own end-to-end test suite; [harness-coverage.md](docs/harness-coverage.md) lists the cases that differ and why.\n\nQ: Why does cdk-nextjs depend upon Next.js v16.3 or higher?\nA: cdk-nextjs builds through the public [Adapter API](https://nextjs.org/docs/app/api-reference/config/next-config-js/adapterPath), and 16.3 is the first version whose build output carries everything it reads (middleware matchers and per-file asset hashes). 16.2 also added the [Image Optimization Caching](https://nextjs.org/docs/app/api-reference/config/next-config-js/incrementalCacheHandlerPath#image-optimization-caching) it relies on. The runtime bundles `@next/routing` at the version it was tested against (see `package.json`), and newer Next.js 16 releases are expected to work.\n\nQ: How does cdk-nextjs support caching in Next.js?<br/>\nA: See [Caching Guide](./docs/caching-guide.md)\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: How can I `cdk bootstrap --cloudformation-execution-policies ...` my AWS Account with limited permissions for cdk-nextjs to deploy?<br />\nA: 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.\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 [OpenNext](https://opennext.js.org).\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"
9035
+ "markdown": "![Version](https://img.shields.io/github/v/release/cdklabs/cdk-nextjs)\n[![npm version](https://img.shields.io/npm/v/cdk-nextjs.svg?style=flat-square)](https://www.npmjs.org/package/cdk-nextjs)\n![License](https://img.shields.io/github/license/cdklabs/cdk-nextjs)\n\n# CDK Next.js Construct Library\n\n<!--BEGIN STABILITY BANNER-->\n\n---\n\n![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)\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).\n- Choose your AWS architecture for Next.js with the supported constructs: `NextjsGlobalFunctions`, `NextjsGlobalContainers`, `NextjsRegionalContainers`, `NextjsRegionalFunctions`.\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 all constructs (except `NextjsRegionalContainers`) to decrease latency and reduce compute costs by serving directly from S3.\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), [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache) and [`'use cache: remote'`](https://nextjs.org/docs/app/api-reference/directives/use-cache-remote) are shared across compute with [Amazon Simple Storage Service (S3)](https://aws.amazon.com/s3/) with supporting metadata in [Amazon DynamoDB](https://aws.amazon.com/dynamodb), and `revalidateTag`/`revalidatePath` reach plain [`'use cache'`](https://nextjs.org/docs/app/api-reference/directives/use-cache) on every instance. See [`'use cache'` and `'use cache: remote'`](#use-cache-and-use-cache-remote).\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- [Bring Your Own Resources](#bring-your-own-resources) — import existing AWS resources (CloudFront distributions, ECS clusters, ALBs, S3 buckets, DynamoDB tables).\n- [AWS GovCloud (US)](https://aws.amazon.com/govcloud-us) compatible with `NextjsRegionalFunctions` and `NextjsRegionalContainers`.\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- Integrate through Next.js's official interfaces. Build on the [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters) API and [`@next/routing`](https://www.npmjs.com/package/@next/routing) rather than Next.js internals, so new Next.js versions rarely break this construct. Where no public interface exists yet, the dependency is listed in [Next.js private APIs](docs/nextjs-private-apis.md).\n- Security first.\n- One architecture does not fit all.\n- Enable customization everywhere.\n\n## Prerequisites\n\n- Next.js app running v16.3 or higher (`next build` fails on older versions). If you don't have one yet - follow [these steps](https://nextjs.org/docs/getting-started) to create one.\n- [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) app either in the same package or separate package. cdk-nextjs supports monorepos.\n- A Docker compatible container engine, but **only** for `NextjsGlobalContainers` and `NextjsRegionalContainers` - we recommend [Rancher Desktop](https://rancherdesktop.io/) with dockerd (moby). The two Functions types deploy zip Lambdas and need no container engine.\n- [Node.js](https://nodejs.org/en) v24 (or LTS)\n\n## Getting Started\n\n1. Install `cdk-nextjs` in the package(s) containing your CDK and Next.js app with `npm i cdk-nextjs`\n2. Deploy your Next.js app to AWS: `cdk deploy`. Make sure you have [AWS credentials](https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html) configured.\n3. Visit URL printed in terminal (CloudFormation Output) to view your Next.js app!\n\nNo `next.config` change is needed: cdk-nextjs runs `next build` itself, and sets [`NEXT_ADAPTER_PATH`](https://nextjs.org/docs/app/api-reference/config/next-config-js/adapterPath) on that build so Next.js loads cdk-nextjs's [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters).\n\n### Registering the adapter yourself\n\nSet `adapterPath` in `next.config` in three cases. An explicit `adapterPath` always wins over `NEXT_ADAPTER_PATH`, so this is also how you pin a specific adapter.\n\n- **cdk-nextjs isn't running your build** — `skipBuild: true`, or you build in CI and hand the output to CDK.\n- **cdk-nextjs isn't a dependency of the Next.js app**, only of the CDK app. cdk-nextjs resolves the adapter from your app's directory, so it can't find it in that layout.\n- **cdk-nextjs is linked from outside your project root** — a `link:`/`file:` dependency on a checkout elsewhere on disk, as this repo's own examples use. The symlink resolves out of the project, and the adapter derives its cache handler path from its own location, so Next.js gets a `cacheHandler` outside `turbopack.root` and Turbopack rejects it. Setting `adapterPath` fixes this because the build resolves it, after whatever put the adapter in place.\n\n```ts\nimport { NextConfig } from \"next\";\n\nconst nextConfig: NextConfig = {\n // ...\n adapterPath: require.resolve(\"cdk-nextjs/adapter\"),\n};\n\nexport default nextConfig;\n```\n\n`require.resolve` works in an ESM `next.config.ts` too, because Next.js transpiles the config to CJS before evaluating it.\n\n### cdk-nextjs Created Dockerfile\n\nFor the Containers types, cdk-nextjs generates a Dockerfile in your Next.js app's directory. It cannot clean the file up after the image is built, so either commit it or gitignore it.\n\nEvery generated Dockerfile starts with the line `# ~~ Generated by cdk-nextjs ~~`, and cdk-nextjs **overwrites** any file carrying it — that way an upgrade that changes how the image is built does not leave a stale Dockerfile behind. To customize it, delete that first line; cdk-nextjs then leaves the file alone. If you edited a generated file without deleting the header, cdk-nextjs saves your version beside it as `<name>.Dockerfile.bak` before replacing it; gitignore that too.\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 WebStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n new NextjsGlobalFunctions(this, \"Nextjs\", {\n buildDirectory: join(import.meta.dirname),\n });\n }\n}\n\nconst app = new App();\n\nnew WebStack(app, \"web-stack\");\n```\n\nSee [examples/](./examples/) for more usage examples.\n\n## Architecture\n\nHow requests are served inside the compute — the adapter runtime, and where it deliberately differs from `next start` — is in [docs/adapter-runtime.md](./docs/adapter-runtime.md).\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))\n\n![NextjsGlobalFunctions architecture: User to CloudFront, which serves S3 static assets and forwards to a Lambda function backed by a DynamoDB table and S3 cache bucket](https://raw.githubusercontent.com/cdklabs/cdk-nextjs/main/docs/diagrams/nextjs-global-functions.svg)\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))\n\n![NextjsGlobalContainers architecture: User to CloudFront, which serves S3 static assets and forwards to an Application Load Balancer and ECS Fargate containers in a VPC, backed by a DynamoDB table and S3 cache bucket](https://raw.githubusercontent.com/cdklabs/cdk-nextjs/main/docs/diagrams/nextjs-global-containers.svg)\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![NextjsRegionalContainers architecture: User to an Application Load Balancer and ECS Fargate containers in a VPC, backed by a DynamoDB table and S3 cache bucket](https://raw.githubusercontent.com/cdklabs/cdk-nextjs/main/docs/diagrams/nextjs-regional-containers.svg)\n\n### `NextjsRegionalFunctions`\n\nArchitecture 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))\n\n![NextjsRegionalFunctions architecture: User to an API Gateway REST API, which serves S3 static assets and forwards to a Lambda function backed by a DynamoDB table and S3 cache bucket](https://raw.githubusercontent.com/cdklabs/cdk-nextjs/main/docs/diagrams/nextjs-regional-functions.svg)\n\n## Configuration\n\nThe variables below are read at runtime by the cache handler inside your deployed\nLambda functions or containers. Set them on the compute through `overrides`:\n\n```ts\n// NextjsGlobalFunctions / NextjsRegionalFunctions\noverrides: {\n nextjsFunctions: {\n functionProps: { environment: { CDK_NEXTJS_MEMORY_CACHE_TTL_MS: \"0\" } },\n },\n},\n\n// NextjsGlobalContainers / NextjsRegionalContainers\noverrides: {\n nextjsContainers: {\n taskImageOptions: { environment: { CDK_NEXTJS_MEMORY_CACHE_TTL_MS: \"0\" } },\n },\n},\n```\n\nValues you pass are merged over the ones the construct sets, so the same mechanism\noverrides the [infrastructure variables](#infrastructure-configuration) too.\n\n### Cache Configuration\n\n#### `CDK_NEXTJS_MEMORY_CACHE_TTL_MS`\n\nTime to live in milliseconds for in-memory cache entries. After this duration, entries expire and are removed from the cache.\n\n**Note**: Every memory hit is checked against the tag revalidation markers, so an entry revalidated on another instance is not served from memory. A tag's marker is read from DynamoDB only on its first use and a rolling re-read every few minutes; in between, revalidations arrive through the revalidation log (one `Query` per [`CDK_NEXTJS_TAG_REFRESH_MS`](#cdk_nextjs_tag_refresh_ms)). Memory still saves the S3 read and body parse. Set this to `0` to disable the memory cache entirely (all requests will fall through to S3 + DynamoDB).\n\n**Default**: `3600000` (1 hour)\n\n**Examples**:\n\n- Short TTL (5 minutes): `300000` - for frequently changing data\n- Medium TTL (1 hour): `3600000` - balanced between freshness and performance\n- Long TTL (24 hours): `86400000` - for mostly static content\n\n**Trade-offs**:\n\n- Lower values: More cache misses, fresher data, higher S3/DynamoDB costs\n- Higher values: Fewer cache misses, better performance, but longer stale data windows\n\n#### `CDK_NEXTJS_MEMORY_CACHE_MAX_ENTRIES`\n\nMaximum number of cache entries to store in memory. When this limit is reached, the least recently used (LRU) entry is evicted.\n\n**Default**: `1000`\n\n**Examples**:\n\n- Small cache: `100` - minimal memory footprint for simple apps\n- Medium cache: `1000` - good balance for typical applications\n- Large cache: `10000` - for high-traffic apps with many unique pages\n\n**Trade-offs**:\n\n- Lower values: Less memory usage, more cache evictions\n- Higher values: More memory usage, fewer cache evictions, better hit rates\n\n**Memory considerations**: Each entry stores the full cache value (HTML, JSON, etc.). A typical page cache might be 10-100KB, so 1000 entries ≈ 10-100MB of memory. Consider your compute environment's memory limits (Lambda: 128MB-10GB, Fargate: 512MB-30GB) and size accordingly.\n\n### `'use cache'` and `'use cache: remote'`\n\nThe adapter registers two [`cacheHandlers`](https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheHandlers)\nnext to the `cacheHandler` it already sets, unless your `next.config` names a\nhandler of its own for either:\n\n| Directive | `cacheHandlers` name | Stored | Tags |\n| --------------------- | -------------------- | -------------------------------- | ----------------------- |\n| `'use cache'` | `default` | each instance's memory | DynamoDB, all instances |\n| `'use cache: remote'` | `remote` | S3 cache bucket, memory in front | DynamoDB, all instances |\n\n- **`'use cache: remote'`** is shared: an entry any instance generates is the one\n every instance serves, until it expires or a tag is revalidated. Use it for\n results you don't want each Lambda instance or task to compute on its own. It\n costs an S3 `GetObject` the first time an instance reads an entry, and a\n `PutObject` per generated entry. Objects live under\n `<buildId>/_use-cache/` in the cache bucket and are pruned with the build.\n- **`'use cache'`** stays per instance, as Next.js intends — but `revalidateTag`,\n `updateTag` and `revalidatePath` now expire it on every instance, not only the\n one that ran them. Next.js's built-in handler keeps tags in process memory, so\n before this every other instance kept serving the revalidated value, even into\n pages re-rendered because of that revalidation.\n\nBoth read the same per-tag marker rows in the revalidation table that ISR and\nthe data cache use. A tag an instance has not seen yet — an entry read from S3,\na page's implicit `revalidatePath` tags — is read from its marker before it is\ntrusted, once per instance.\n\nAfter that, an instance doesn't re-read the tags it tracks to learn what\nchanged. Each `revalidateTag`/`updateTag` also writes a row to a revalidation\nlog in the same table (`pk = <buildId>#log`, expiring after 15 minutes through\nthe table's `ttl` attribute). At most once per\n[`CDK_NEXTJS_TAG_REFRESH_MS`](#cdk_nextjs_tag_refresh_ms),\neach instance sends one DynamoDB `Query` for the rows written since its last\none and applies those for tags it tracks. So a revalidation on another instance\nis honored within that window (1 second by default), and on the instance that ran\nit immediately. An idle instance's query costs 0.5 RCU a second, where\nre-reading up to 1000 tracked tags cost about 500. Each tag's marker is still\nre-read every 7.5 to 10 minutes, a few each second rather than all at once (about 8\nRCU a second at the most an instance tracks, 10,000 tags). After a gap the log\nmay no longer cover (a Lambda frozen between invocations, a run of failed\nqueries), an instance forgets its tracked markers and reads each again as it's\nneeded. ISR and the data cache share the same copy of the markers, so one\n`revalidateTag` writes each tag's rows once and one `Query` serves them all.\n\nIf you pass your own `revalidationTable`, enabling TTL on its `ttl` attribute is\nrecommended. Without it the log rows (about 100 bytes per revalidated tag) are\nkept until a deploy replaces their build, whose post-deploy step deletes them.\n\nTwo instances that generate the same `'use cache: remote'` entry at the same\nmoment both store it; each serves its own copy until that copy's `revalidate`\ntime, after which S3's is used.\n\n#### `CDK_NEXTJS_TAG_REFRESH_MS`\n\nHow often, at most, in milliseconds, an instance asks the revalidation log what\nother instances revalidated, for `'use cache'`, ISR and the data cache alike. A\n`revalidateTag` elsewhere goes unseen for up to about the window plus a second\n(2 s by default), since `'use cache'` doesn't wait for the answer - and for\nlonger while a query is slow or failing, or for a page render that started\ninside the window, which reads what the instance knew when it began. It's one DynamoDB `Query`,\nhowever many tags the instance tracks, shared by every request on the instance\nduring the window. `0` asks before every cache check, and waits for the answer\n(`'use cache'` only while the instance holds an entry the answer could expire).\nOtherwise `'use cache'` reads don't wait for it, and it applies from the\ninstance's next request. The exception is an instance that hasn't caught up for\nover a second past the window (it sat idle or was frozen): it waits for the\nanswer, before rendering the page for a page request. `'use cache: remote'`\nalways waits.\n\n**Default**: `1000`\n\n#### `CDK_NEXTJS_USE_CACHE_MEMORY_BYTES`\n\nSize bound, in bytes, of each handler's in-memory store: all of `'use cache'`,\nand the memory tier in front of S3 for `'use cache: remote'`. Least recently used\nentries are evicted first.\n\n**Default**: `52428800` (50 MB, Next.js's own default)\n\n### Infrastructure Configuration\n\nThe construct sets these itself and they typically don't need to be modified:\n\n#### `CDK_NEXTJS_BUILD_ID`\n\nUnique identifier for the Next.js build. Used for cache isolation between deployments.\n\n#### `CDK_NEXTJS_CACHE_BUCKET_NAME`\n\nS3 bucket name for storing cached data (optimized images, data cache, full route cache, `'use cache: remote'`).\n\n#### `CDK_NEXTJS_REVALIDATION_TABLE_NAME`\n\nDynamoDB table name for tracking cache revalidations and tag-to-cache-key mappings.\n\n#### `DEBUG`\n\nNot set by default. Set it to `cdk-nextjs:*` to enable debug logs. This is especially useful to see cache handler activity.\n\n### `next.config.js` options cdk-nextjs reads\n\nBoth are read out of your build, so you set them in one place — your app — and the\ninfrastructure follows.\n\n#### `basePath`\n\nBecomes the S3 key prefix for static assets and the prefix on every CloudFront\ncache behavior. See [Resource Isolation](#resource-isolation); the `basePath`\nprop only exists to be explicit about it.\n\n#### `assetPrefix`\n\n- **A path** (`assetPrefix: \"/cdn\"`) — Next.js emits bundle URLs as\n `/cdn/_next/static/...`, on top of `basePath` rather than under it, while the\n objects stay in S3 under `<basePath>/_next/static/...`. `NextjsGlobalFunctions`\n and `NextjsGlobalContainers` add a cache behavior for\n `<assetPrefix>/_next/static*` pointing at the assets bucket, with a CloudFront\n Function that rewrites the prefix back to the S3 keys. It costs one of the 25\n cache behaviors cdk-nextjs budgets for you. **Not supported on\n `NextjsRegionalFunctions` or `NextjsRegionalContainers`** — nothing there maps\n the prefix back, so bundles would 404; synth warns if your app sets one.\n- **An absolute URL** (`assetPrefix: \"https://cdn.example.com\"`) — names an origin\n cdk-nextjs doesn't serve, so nothing is added, on any construct. Point that host\n at the assets bucket yourself, including the `basePath` prefix the objects are\n stored under.\n- **An absolute URL with a path** (`assetPrefix: \"https://cdn.example.com/cdn\"`) —\n its path is treated exactly like the path case above, because `next build`\n compiles a `/cdn/_next/:path+` rewrite of its own: `next start` serves bundles\n under that path too, so the Global constructs answer there as well. Useful when\n that host is a second domain on the same distribution.\n\n## Splitting a Large App Across Functions\n\nOnly for `NextjsGlobalFunctions` and `NextjsRegionalFunctions`, and only if you\nneed it. AWS Lambda caps a function's unzipped code at 250 MB. If your app\nexceeds it, cdk-nextjs fails at synth with the measured size and points you here:\n\n```\nFunction group \"default\" is 274 MB unzipped, over Lambda's 250 MB limit. Use the\n`functionGroups` prop to package routes into separate functions. Note that\nsplitting only removes route-local code — anything reachable from a shared layout\nor the `next` runtime is in every group.\n```\n\n`functionGroups` declares which routes get their own Lambda. Everything you do\nnot name stays on the `default` function:\n\n```ts\nnew NextjsGlobalFunctions(this, \"Nextjs\", {\n buildDirectory: join(import.meta.dirname, \"..\", \"web\"),\n functionGroups: [\n { name: \"reports\", routes: [\"/dashboard/reports/**\"] },\n { name: \"admin\", routes: [\"/admin\", \"/admin/**\", \"/settings\"] },\n ],\n});\n```\n\nEach group becomes one Lambda function containing only the routes it owns (plus\nthe framework closure every function needs), and one CloudFront behavior — or API\nGateway resource, for `NextjsRegionalFunctions` — per pattern.\n\n**Route patterns** are either an exact path (`/settings`) or a subtree\n(`/admin/**`). A subtree owns what is _under_ it, not the path itself:\n`/admin/**` does not claim `/admin`. To own a page and everything under it, list\nboth, as the example above does: `[\"/admin\", \"/admin/**\"]`. Where two groups\ncould both match, the longest pattern wins, so `/api/**` and `/api/reports/**`\ncan coexist in different groups. Dynamic segments (`/blog/[slug]`), route group\nsegments (`/(marketing)/about`), `/`, and `/**` are rejected at synth —\nCloudFront matches literal path prefixes and cannot express them. `/index` is\naccepted for an App Router `app/index/page.tsx`, but not for a Pages Router home\npage, which is the same file as `/`.\n\n**What is routed for you.** Patterns decide which _files_ a group packages; the\nedge then has to send every URL those files serve to that group. cdk-nextjs\nderives these without extra patterns:\n\n- A Pages Router page's data URL, `/_next/data/<buildId>/<page>.json`. The\n behavior carries the literal build ID, so it changes on every deploy; a\n client still on the previous build falls through to the `default` function,\n which answers 404, and the Next.js client reloads the page.\n- The `trailingSlash` form of an exact pattern (`/pricing/`). CloudFront gets a\n behavior for it; on `NextjsRegionalFunctions` none is needed, because API\n Gateway already routes `/pricing/` to the `/pricing` resource.\n- The parent of an optional catch-all. `/shop/**` moving\n `app/shop/[[...slug]]/page.tsx` also routes `/shop`, which the same file\n serves. Do not add `/shop` yourself: it matches no route and is rejected.\n- An [interception route](https://nextjs.org/docs/app/api-reference/file-conventions/intercepting-routes)\n is packaged with the group that owns the URL it intercepts, not by its own\n path: `app/feed/(..)photo/[id]` follows `/photo/[id]`, because a soft\n navigation requests `/photo/1` and Next.js rewrites it in whichever function\n receives it.\n\n**What synth rejects.** After assigning routes, cdk-nextjs replays the\nCloudFront behaviors over every URL each file serves and fails when one would\nreach a function without its file, naming the file, the URL and the pattern to\nadd. That covers:\n\n- A file behind several templates that a pattern only partly covers — root\n params (`app/[locale]/page.tsx` prerendered as `/en` and `/de`) grouped with\n `/en` alone. A dynamic first segment can never be routed, so such a file stays\n in `default`.\n- An intercepted URL space split between groups (`/photo/[id]` in one,\n `/photo/1` in another), since the intercepting file cannot be in both.\n- A `next.config` rewrite whose source reaches one group and whose destination\n file is in another: rewrites run inside the function that received the\n request. Only rewrites with a literal destination are checked.\n- A group pattern that duplicates a top-level `public/` entry's behavior\n (`public/docs/` and `/docs/**`), or sits under one (`/docs/guide/**`), which\n would send the group's routes to S3.\n\nNot checked, because it is only known at request time: **a middleware\n`NextResponse.rewrite()`** to a route in another group reaches the function that\nreceived the original URL, which lacks the route's file. It answers 404 (or a\n308 to the canonical URL when only the case differs) and logs a warning naming\nthe group that owns the route. Keep a middleware rewrite's source and\ndestination in the same group. The same goes\nfor a `next.config` rewrite whose destination is built from its parameters\n(`/b/:slug` → `/blog/:slug`), and for a dynamic segment of a `default` route\nthat overlaps a group's literal path (`/[section]/intro` against `/docs/**`).\nLikewise **a Pages Router `res.revalidate()`** renders the page in the function\nthat called it, so it can only revalidate pages in its own group; the error\nnames the group that owns the page. Use `revalidatePath()` or `revalidateTag()`\nacross groups. And **an `<Image>` whose `src` is a route in another group**\n(`/api/avatar/42` under an `/api/**` group) can't be optimized: `/_next/image`\nruns in the `default` function, which fetches a local source that isn't a\n`public/` or `_next/static` file by running its route in-process, and it doesn't\ncarry that route, so the image request fails. Keep image-serving routes in\n`default`, or point `src` at a `public/` file or a remote URL.\n\n**What splitting does and does not save.** Every function ships the same `next`\nruntime closure, so splitting only moves route-_local_ code and its dependencies.\nA group whose routes import a large library is worth extracting; splitting an app\nin half does not halve either function.\n\nNotes:\n\n- Group names must be valid CDK construct ids (letters, digits, `-`). `default`\n is reserved.\n- A pattern that matches no route in the build is a synth error, not a silent\n no-op — it is almost always a typo.\n- Cannot be combined with `i18n`: locale-prefixed routes would need one\n CloudFront behavior per locale per pattern.\n- Group patterns (and the routes derived from them above) count against the\n same CloudFront behavior budget as your `public/` entries (see\n [Limitations](#limitations)).\n- Per-group `overrides` let you size each function independently:\n `{ name: \"reports\", routes: [...], overrides: { functionProps: { memorySize: 2048 } } }`.\n\n## Running Code on Every Viewer Request\n\n`NextjsGlobalFunctions` and `NextjsGlobalContainers` take a\n`viewerRequestFunctionCode` prop: CloudFront Function code that runs first on\nevery request, on every behavior cdk-nextjs adds — pages, API routes,\n`_next/image`, `_next/static` and `public/` files alike. It's the place for a\ngate the whole site has to pass, such as HTTP Basic auth before launch:\n\n```ts\nimport { FunctionCode, KeyValueStore } from \"aws-cdk-lib/aws-cloudfront\";\n\nconst credentials = new KeyValueStore(this, \"Credentials\");\nnew NextjsGlobalFunctions(this, \"Nextjs\", {\n buildDirectory: join(import.meta.dirname),\n viewerRequestKeyValueStore: credentials,\n viewerRequestFunctionCode: FunctionCode.fromInline(`\n import cf from \"cloudfront\";\n const kvs = cf.kvs();\n async function viewerRequest(event) {\n const auth = event.request.headers.authorization;\n try {\n if (auth && auth.value === \"Basic \" + (await kvs.get(\"basic-auth\"))) {\n // verified: don't pass the site's credentials on to the origin\n delete event.request.headers.authorization;\n return;\n }\n } catch (e) {\n // no \"basic-auth\" key yet: stay locked\n }\n return {\n statusCode: 401,\n statusDescription: \"Unauthorized\",\n headers: { \"www-authenticate\": { value: 'Basic realm=\"preview\"' } },\n };\n }\n `),\n});\n```\n\nThen put the credentials in the store, outside the template:\n\n```sh\nKVS_ARN=... # the store's ARN\naws cloudfront-keyvaluestore put-key --kvs-arn \"$KVS_ARN\" \\\n --key basic-auth --value \"$(printf 'user:pass' | base64 | tr -d '\\n')\" \\\n --if-match \"$(aws cloudfront-keyvaluestore describe-key-value-store \\\n --kvs-arn \"$KVS_ARN\" --query ETag --output text)\"\n```\n\nThe code must define `viewerRequest(event)`, as a function (`async` or not)\nor a `var`/`let`/`const`. It's a CloudFront Function handler in all but name:\nreturn a response to answer the viewer, or the request (or nothing) to carry\non.\n\nWhy not a function of your own on viewer-request? CloudFront allows one per\nevent type per behavior, and on Global Functions cdk-nextjs's own one\noverwrites `X-Forwarded-Host` and redirects repeated slashes. So your code is\nspliced into that function, ahead of cdk-nextjs's logic, which still runs after\nit, so your code can't undo the `X-Forwarded-Host` overwrite. Middleware can't\ndo this instead: on Global Functions CloudFront signs the request to the\nFunction URL with the `Authorization` header, and static assets never reach the\nserver at all.\n\n- cdk-nextjs's CloudFront Functions run on `cloudfront-js-2.0`, so your code\n can be `async`, and `import cf from \"cloudfront\"` works when it comes first,\n as it does above.\n- `viewerRequestKeyValueStore` is associated with every viewer-request function\n your code is copied into (up to three, one per kind of behavior), so\n `cf.kvs()` reads it with no ID wherever the code runs. Credentials written\n inline in the code instead end up in the CloudFormation template.\n- The combined function, cdk-nextjs's code included, must fit CloudFront's\n 10 KB limit; synth fails if it doesn't (or warns, if the code contains a\n CDK token, whose size isn't known until deploy).\n- Your code shares the file with cdk-nextjs's `handler`, so it can't use the\n name `handler` at all, even in a comment or a string; synth refuses it.\n- A viewer-request association in `overrides.*BehaviorOptions.functionAssociations`\n on a behavior this covers is refused at synth; put that logic in\n `viewerRequestFunctionCode` instead. So is\n `overrides.distributionProps.defaultBehavior` without a `basePath`, since it\n would replace the default behavior the code runs on; customize it through\n `overrides.dynamicBehaviorOptions`.\n- A bring-your-own `distribution`'s default behavior is yours, so it isn't\n covered. Only the behaviors cdk-nextjs adds are; under a `basePath`, those\n include the ones that stand in for the default behavior.\n\n## Bring Your Own Resources\n\ncdk-nextjs supports importing existing AWS resources instead of creating new ones. This is especially useful for per-branch (MR/PR) environments where you deploy shared infrastructure (VPC, ECS cluster, ALB) once and spin up lightweight branch stacks that reuse it.\n\n### Supported Resources\n\n| Resource | Prop | Available On |\n| --------------------------- | -------------------- | ---------------------------------------------------- |\n| S3 Cache Bucket | `cacheBucket` | All constructs |\n| DynamoDB Revalidation Table | `revalidationTable` | All constructs |\n| S3 Static Assets Bucket | `staticAssetsBucket` | All constructs |\n| CloudFront Distribution | `distribution` | `NextjsGlobalFunctions`, `NextjsGlobalContainers` |\n| ECS Cluster | `ecsCluster` | `NextjsGlobalContainers`, `NextjsRegionalContainers` |\n| ALB | `alb` | `NextjsGlobalContainers`, `NextjsRegionalContainers` |\n\n### Resource Isolation\n\n- **Cache bucket and DynamoDB table** must be dedicated to one deployment. Sharing either between deployments (branches, stages, apps) is not supported: each deploy's post-deploy step prunes every cache object and revalidation entry that isn't from its own current build, so deploying one branch wipes the others' caches. Buckets and tables are cheap, so give each deployment its own, or leave `cacheBucket`/`revalidationTable` unset and let cdk-nextjs create them (they are removed with the stack).\n- **Static assets bucket** can be shared, but only between deployments with different `basePath`s, which become their S3 key prefixes. Pruning only looks at `<basePath>/_next/`, so it never touches another prefix. Two deployments under the same prefix (for example two subdomain previews both at the root) overwrite each other's `public/` files and prune each other's `_next/` assets once they are past the prune TTL (30 days by default), so give those their own buckets. `NextjsGlobalFunctions` and `NextjsGlobalContainers` read the `basePath` out of your Next.js build and use it as the S3 key prefix, since CloudFront serves assets from S3 by request path and the two can't differ. Set the `basePath` prop only if you want to be explicit about it; a value that disagrees with your app's fails at synth. Each deployment also adds an ownership tag per static asset upload (1 to 3, by whether the build has `public/` files and service workers) to a bucket created in your CDK app; an imported bucket gets none. S3 allows 50 tags per bucket, so such a bucket holds at least 16 deployments.\n\n### Shared ALB and `removeAutoCreatedListener()`\n\n`ApplicationLoadBalancedFargateService` always creates a listener on port 80 — there is no opt-out. When you import an ALB that already has a listener on that port, the duplicate causes a deployment failure. Since CDK doesn't expose a way to prevent this, `removeAutoCreatedListener()` surgically removes the generated CloudFormation resources: the `CfnListener`, its security group ingress rule, rebuilds the ECS service `DependsOn` without the deleted listener, and removes auto-created `CfnOutput` resources:\n\n```ts\nconst nextjs = new NextjsRegionalContainers(this, \"Nextjs\", {\n // ...\n alb: sharedAlb,\n ecsCluster: sharedCluster,\n});\nnextjs.nextjsContainers.removeAutoCreatedListener();\n```\n\n### Examples\n\nSee [examples/bring-your-own/](./examples/bring-your-own/) for a complete deployable example with a shared VPC, ECS cluster, and ALB, per-branch host-header routing, and a cache bucket, revalidation table, and static assets bucket per branch.\n\n## Preview Environments (Per-Branch Deployments)\n\ncdk-nextjs can deploy ephemeral preview environments per merge request (MR) or pull request (PR). The recommended approach uses subdomain-based routing (`pr-123.app.example.com`) so each preview environment runs the same Next.js build as production — no `basePath` configuration or separate builds required.\n\nSee [examples/bring-your-own/](./examples/bring-your-own/) for a fully deployable example using `NextjsRegionalContainers` with a shared VPC, ALB, and ECS Cluster (connected via SSM Parameter Store), and S3 buckets and a DynamoDB table owned by each branch stack.\n\nEach preview environment needs its own cache bucket and revalidation table (see [Resource Isolation](#resource-isolation)). Since every preview serves the same build at the root, give each its own static assets bucket too. Leaving `cacheBucket`, `revalidationTable`, and `staticAssetsBucket` unset does this: cdk-nextjs creates them in the branch stack and deletes them when it's torn down.\n\n### Prerequisites\n\n- Wildcard DNS record: `*.app.example.com` → your routing layer (ALB, CloudFront, API Gateway)\n- Wildcard ACM certificate: `*.app.example.com`\n\n### Per-Architecture Recommendations\n\n#### `NextjsGlobalContainers` and `NextjsRegionalContainers` (ALB-based)\n\nSubdomain routing via ALB host-based listener rules. This is the fastest and simplest approach. For `NextjsGlobalContainers`, CloudFront forwards the `Host` header to the ALB origin, so the ALB handles all branch routing — no CloudFront changes needed per branch.\n\nSee [examples/bring-your-own/](./examples/bring-your-own/) for the full implementation.\n\n#### `NextjsRegionalFunctions` (API Gateway)\n\nSubdomain routing via API Gateway custom domain mappings.\n\n1. Per branch, deploy a cdk-nextjs stack that creates its own API Gateway, Lambda function, S3 buckets, and DynamoDB table\n2. Create an API Gateway custom domain (`pr-123.app.example.com`) mapped to the branch's API stage\n3. Tear down the branch stack on MR close\n\n#### `NextjsGlobalFunctions` (Lambda + CloudFront)\n\nRequires a separate cdk-nextjs stack per branch, each with its own CloudFront distribution. CloudFront cannot route to different Lambda Function URL origins based on the `Host` header — origin selection is determined by cache behavior path patterns, not request headers.\n\n1. Per branch, deploy a full cdk-nextjs stack that creates its own CloudFront distribution, Lambda function, S3 buckets, and DynamoDB table\n2. Point `pr-123.app.example.com` DNS to the branch's CloudFront distribution\n3. Tear down the branch stack on MR close\n\nNote: CloudFront distributions take several minutes to create/update, so this architecture has the slowest preview environment spin-up time.\n\n## Limitations\n\n- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers` (which use CloudFront), each top level file/directory in `public/` takes a CloudFront cache behavior, and a distribution's default quota is 75 behaviors (cdk-nextjs uses 3 to 6 itself). 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. If you raise the quota for your account, set `maxCacheBehaviors` on the distribution props (`overrides.nextjsGlobalFunctions.nextjsDistributionProps`, or the Containers equivalent) to match. The synth check only counts the behaviors cdk-nextjs adds, so if you pass your own `distribution` (or add behaviors through `overrides.nextjsDistribution.distributionProps`), lower `maxCacheBehaviors` by the behaviors it already has. See [CloudFront Quotas](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html) for more information.\n- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers`, on-demand revalidation ([revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath), [revalidateTag](https://nextjs.org/docs/app/api-reference/functions/revalidateTag)) creates the CloudFront invalidations for you (so does the Pages Router's `res.revalidate()`, for the page's HTML and `_next/data` copies), but [invalidations](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html) are eventually consistent: until one completes (usually seconds, occasionally minutes), some edge locations can still serve the previous copy.\n - **Burst limit.** CloudFront allows 15 wildcard invalidation paths in progress per distribution, and each page cdk-nextjs invalidates is one wildcard path (`/blog*`). Next.js sends every `revalidatePath`/`revalidateTag` from one request as a single call, one invalidation per cache-life profile, however many pages it covers. A Pages Router `res.revalidate()` sends one invalidation per call, and a page regenerated after a stale-while-revalidate `revalidateTag(tag, profile)` sends one more when it lands. When the quota is full, cdk-nextjs retries the request as a single `/*` (a colder edge, never a stale page). If that is also rejected, it logs `Failed to create CloudFront invalidation` and the page stays stale at the edge until its `s-maxage` expires.\n - **For bulk updates** (a CMS webhook touching many pages), call `revalidateTag` with a tag the pages share, or `revalidatePath` for each page within one request, rather than looping `res.revalidate()`. If you need to know when invalidations are dropped, add a CloudWatch Logs metric filter on that log line.\n- If using `NextjsGlobalFunctions`, a client-supplied `Authorization` header does not reach your app: CloudFront signs each request to the Lambda Function URL with SigV4, which uses that header. Send credentials under a different name (e.g. `x-authorization`) and read that header in your app. cdk-nextjs does not rename it for you — it no longer uses [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter), so `AWS_LWA_AUTHORIZATION_SOURCE` no longer applies.\n- If using `NextjsGlobalFunctions`, a `POST` or `PUT` with a request body must carry an `x-amz-content-sha256` header holding the hex SHA-256 of that body. This is [AWS behavior](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-lambda.html), not a cdk-nextjs choice: CloudFront signs the origin request to the Lambda Function URL with SigV4 but does not hash the body, and Lambda rejects an unsigned payload with `403 InvalidSignatureException`. Requests from your own pages are handled for you — cdk-nextjs injects a `fetch`/`XMLHttpRequest` wrapper into the client bundle that adds the header, so server actions, route handlers, `fetch` and `XMLHttpRequest` from the browser work untouched, whatever the body type. The exception is a native `<form method=\"post\">` submitted before the page hydrates (a server action form without JavaScript, or clicked before the bundle loads): the browser sends it, not the wrapper, so it has no header and gets the 403. **Anything that is not that browser bundle has to add the header itself**: `curl`, a mobile app, a webhook provider, another service calling your API routes. Server-to-server callers can compute it with the AWS SDK's `Sha256`, or with `crypto.createHash(\"sha256\").update(body).digest(\"hex\")`. The other three deployment types are unaffected.\n- If using `NextjsGlobalFunctions`, a `HEAD` request is answered with `content-length: 0`, whatever length your handler declares. This is Lambda Function URL behavior: the same runtime's declared length reaches the client through API Gateway (`NextjsRegionalFunctions`) and from an ALB, with or without CloudFront in front (the two Containers types).\n- Group patterns declared via [`functionGroups`](#splitting-a-large-app-across-functions) also count against the CloudFront behavior limit above.\n- 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 — leave the construct's `basePath` prop unset when you do, since API Gateway strips the stage before matching resources. API Gateway strips the stage from the path it passes to Lambda; cdk-nextjs puts it back for an app whose `basePath` starts with it, reading the stage off each request, so no middleware is needed and a renamed stage needs no configuration. Mapping a custom domain at the root avoids all of this — see [examples/regional-functions/README.md](./examples/regional-functions/README.md#with-a-custom-domain-no-stage-workarounds).\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`, use [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)\n- 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.\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| Dynamic Revalidate Tag % | 1% |\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### NextjsGlobalFunctions\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=23611f6fea87ef05d5fe87c33135ddde43b17a98)\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 | 20 GB storage, 1M GET, 250K PUT requests | $2.11 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| Total | | $8.09 |\n\n### NextjsGlobalContainers\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=02f0073e612d1eee2a7ccace2c636adc5f0acab7)\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 | 20 GB storage, 1M GET, 250K PUT requests | $2.11 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| VPC | NAT Gateway, 2 AZs | $65.70 |\n| Total | | $121.25 |\n\n### NextjsRegionalContainers\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=e214abe60eb4e24fc5866d07ef4355393261af3c)\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| S3 | 10 GB storage, 250K GET, 250K PUT requests | $1.58 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| VPC | NAT Gateway, 2 AZs | $65.70 |\n| Total | | $139.00 |\n\n### NextjsRegionalFunctions\n\n[AWS Pricing Calculator](https://calculator.aws/#/estimate?id=60da38c7993c1baeee2fee4bd19ba6441608bb15)\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| API Gateway | 2M requests | $7.00 |\n| S3 | 10 GB storage, 250K GET, 250K PUT requests | $1.58 |\n| DynamoDB | 10 GB storage, 5K Reads, 5K Writes | $2.50 |\n| Total | | $11.08 |\n\n## Performance\n\nMeasured with [k6](https://grafana.com/docs/k6/latest/) from EC2 in us-east-1, the region of the stacks under test (one load generator per stack), against a small benchmark app ([`examples/bench-app`](./examples/bench-app)) that makes no calls outside its own stack. Functions run the default 2048 MB Lambda functions. Containers run the default 1 vCPU / 2 GB Fargate tasks, with CPU autoscaling from 2 to 10 tasks added (the default is one task and no autoscaling). Methodology, caveats, and how to reproduce the numbers: [`examples/load-tests`](./examples/load-tests).\n\nWhat each route measures:\n\n- `static-asset`, `static`, `image`: CloudFront's cache on the Global constructs, and the construct itself on the Regional ones.\n- `isr`: the cache until the page is stale (10 s), then a background revalidation through the S3 + DynamoDB cache.\n- `ssr`, `stream`, `rsc`, `api`: the construct's compute on every request, on every construct.\n\n<!-- tables generated by `pnpm report` in examples/load-tests -->\n\n| Construct | `ssr` at 10 req/s | `ssr` at 50 req/s | `ssr` capacity | `isr` capacity | Cold start p50 |\n| -------------------------- | ----------------- | ----------------------------------------- | -------------- | -------------- | -------------- |\n| `NextjsGlobalFunctions` | 36 / 103 | 33 / 84 | ≥ 6560 req/s | ≥ 6560 req/s | 1390 ms |\n| `NextjsGlobalContainers` | 19 / 44 | 18 / 219 | 194 req/s | ≥ 6400 req/s | – |\n| `NextjsRegionalContainers` | 22 / 172 | 1972 / 39536 ⚠️ 0.54% errors, 76% dropped | 675 req/s | ≥ 6075 req/s | – |\n| `NextjsRegionalFunctions` | 32 / 114 | 30 / 103 | ≥ 6560 req/s | ≥ 6560 req/s | 1380 ms |\n\n_Latency is p50 / p99 in ms, with every route loaded at that rate at once. Capacity is the highest rate sustained with p99 under 1000 ms and under 1% errors._\n\nWhat this means for choosing one:\n\n- **Functions constructs scale with no sizing.** Both held at least 6,560 req/s of SSR, the load generator's limit, at the same latency as at 10 req/s. The cost is a cold start of about 1.4 s on a new execution environment.\n- **Containers constructs are fastest per request but need sizing.** Two 1 vCPU tasks served SSR at 19–22 ms p50 against Lambda's ~30 ms, but tasks take minutes to add. Past capacity they don't degrade gradually: tasks too busy to answer the ALB health check are replaced, which leaves fewer tasks for the same load. Leave headroom.\n- **CloudFront carries the Global constructs' cached traffic.** Prerendered pages, ISR hits, images and assets were answered at the edge in 2–3 ms at every rate. On the Regional constructs every request reaches the construct: `NextjsRegionalContainers` serves assets and image optimization from the same tasks, so 50 req/s on every route at once (400 req/s) is already more than two tasks handle.\n- **Cached pages scale on every construct.** ISR hits held at least 6,000 req/s on all four: at the edge on the Global constructs, and through the S3 + DynamoDB cache on the Regional ones, where each instance holds a tag's revalidation marker for a second (`CDK_NEXTJS_TAG_REFRESH_MS`, see the [Caching Guide](./docs/caching-guide.md)).\n\n<details>\n<summary><code>NextjsGlobalFunctions</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | 250 req/s | 1000 req/s | CDN hits |\n| ------------- | --------- | --------- | --------- | ---------- | -------- |\n| static-asset | 2.1 / 4.8 | 2.1 / 4.7 | 2.0 / 4.9 | 2.1 / 11 | 100% |\n| static | 3.3 / 7.5 | 3.2 / 6.8 | 3.1 / 7.3 | 3.2 / 13 | 100% |\n| isr | 3.3 / 7.4 | 3.3 / 7.7 | 3.2 / 7.2 | 3.2 / 12 | 100% |\n| ssr | 36 / 103 | 33 / 84 | 31 / 86 | 29 / 73 | 0% |\n| stream | 233 / 268 | 230 / 261 | 228 / 259 | 226 / 252 | 0% |\n| stream (TTFB) | 32 / 89 | 29 / 66 | 27 / 65 | 25 / 57 | |\n| rsc | 32 / 67 | 28 / 61 | 27 / 60 | 25 / 52 | 0% |\n| api | 29 / 79 | 26 / 55 | 24 / 61 | 23 / 47 | 0% |\n| image | 3.2 / 6.3 | 3.1 / 6.8 | 3.1 / 7.0 | 3.1 / 12 | 100% |\n\nCapacity: `isr` ≥ 6560 req/s, `ssr` ≥ 6560 req/s.\n\nCold start, time to first byte of `/ssr` on a new execution environment: p50 1390 ms, p90 1451 ms (warm: 84 ms).\n\nBrowser, p75 in ms, under 50 req/s per route:\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | --- | ---- | ---------------------- |\n| static | 76 | 13 | 15 |\n| ssr | 80 | 39 | 53 |\n| isr | 52 | 8.7 | 12 |\n| stream | 64 | 34 | 38 |\n| image | 52 | 6.7 | 10 |\n\n</details>\n\n<details>\n<summary><code>NextjsGlobalContainers</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | CDN hits |\n| ------------- | --------- | --------- | -------- |\n| static-asset | 1.4 / 3.9 | 1.5 / 3.7 | 100% |\n| static | 1.9 / 4.8 | 1.8 / 3.7 | 100% |\n| isr | 2.0 / 4.4 | 1.7 / 4.0 | 100% |\n| ssr | 19 / 44 | 18 / 219 | 0% |\n| stream | 217 / 242 | 217 / 359 | 0% |\n| stream (TTFB) | 17 / 45 | 16 / 207 | |\n| rsc | 12 / 26 | 12 / 86 | 0% |\n| api | 11 / 23 | 10 / 81 | 0% |\n| image | 2.0 / 4.7 | 1.7 / 4.1 | 100% |\n\nCapacity: `isr` ≥ 6400 req/s, `ssr` 194 req/s.\n\nBrowser, p75 in ms, under 50 req/s per route:\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | --- | ---- | ---------------------- |\n| static | 88 | 12 | 17 |\n| ssr | 80 | 26 | 39 |\n| isr | 56 | 6.1 | 13 |\n| stream | 64 | 20 | 25 |\n| image | 52 | 5.4 | 11 |\n\n</details>\n\n<details>\n<summary><code>NextjsRegionalContainers</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | CDN hits |\n| ------------- | --------- | ----------------------------------------- | -------- |\n| static-asset | 18 / 159 | 1698 / 28824 ⚠️ 0.40% errors, 72% dropped | no CDN |\n| static | 41 / 163 | 916 / 28298 ⚠️ 0.46% errors, 66% dropped | no CDN |\n| isr | 40 / 169 | 697 / 27146 ⚠️ 0.36% errors, 57% dropped | no CDN |\n| ssr | 22 / 172 | 1972 / 39536 ⚠️ 0.54% errors, 76% dropped | no CDN |\n| stream | 221 / 354 | 1909 / 27423 ⚠️ 0.44% errors, 72% dropped | no CDN |\n| stream (TTFB) | 19 / 166 | 1881 / 27162 | |\n| rsc | 9.4 / 64 | 433 / 26066 ⚠️ 0.25% errors, 39% dropped | no CDN |\n| api | 6.9 / 55 | 429 / 26041 ⚠️ 0.25% errors, 38% dropped | no CDN |\n| image | 140 / 440 | 1599 / 27489 ⚠️ 0.22% errors, 69% dropped | no CDN |\n\nCapacity: `isr` ≥ 6075 req/s, `ssr` 675 req/s.\n\nBrowser, p75 in ms, under 10 req/s per route. `static` is each visit's first page: on a plain-HTTP origin, Chrome tries HTTPS first and falls back after about 3 s (HTTPS-Upgrades), which real visitors pay too. Put a certificate on the ALB to avoid it.\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | ---- | ---- | ---------------------- |\n| static | 3100 | 3047 | 16 |\n| ssr | 68 | 14 | 27 |\n| isr | 88 | 43 | 13 |\n| stream | 48 | 11 | 13 |\n| image | 212 | 38 | 9.6 |\n\n</details>\n\n<details>\n<summary><code>NextjsRegionalFunctions</code></summary>\n\nLatency per route, p50 / p99 in ms, with every route at the same rate at once:\n\n| Route | 10 req/s | 50 req/s | 250 req/s | 1000 req/s | CDN hits |\n| ------------- | --------- | --------- | --------- | ---------- | -------- |\n| static-asset | 34 / 76 | 32 / 72 | 30 / 72 | 30 / 68 | no CDN |\n| static | 58 / 138 | 57 / 140 | 57 / 147 | 57 / 127 | no CDN |\n| isr | 58 / 149 | 56 / 124 | 56 / 145 | 55 / 125 | no CDN |\n| ssr | 32 / 114 | 30 / 103 | 29 / 115 | 29 / 98 | no CDN |\n| stream | 229 / 293 | 227 / 288 | 227 / 299 | 226 / 282 | no CDN |\n| stream (TTFB) | 27 / 85 | 25 / 84 | 25 / 97 | 24 / 76 | |\n| rsc | 27 / 76 | 26 / 73 | 25 / 83 | 25 / 70 | no CDN |\n| api | 24 / 84 | 22 / 70 | 22 / 97 | 22 / 67 | no CDN |\n| image | 127 / 210 | 125 / 221 | 125 / 236 | 123 / 211 | no CDN |\n\nCapacity: `isr` ≥ 6560 req/s, `ssr` ≥ 6560 req/s.\n\nCold start, time to first byte of `/ssr` on a new execution environment: p50 1380 ms, p90 1442 ms (warm: 71 ms).\n\nBrowser, p75 in ms, under 50 req/s per route:\n\n| Route | LCP | TTFB | Client-side navigation |\n| ------ | --- | ---- | ---------------------- |\n| static | 128 | 70 | 17 |\n| ssr | 88 | 35 | 50 |\n| isr | 108 | 62 | 13 |\n| stream | 64 | 31 | 36 |\n| image | 220 | 60 | 9.6 |\n\n</details>\n\n## Guides\n\n- [Caching Guide](./docs/caching-guide.md)\n- [Pruning Guide](./docs/pruning-guide.md)\n- [Native Dependencies Guide](./docs/native-dependencies-guide.md)\n- [Next Build Output Guide](./docs/next-build-output-guide.ts)\n- [Development Guide](./docs/development-guide.ts)\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) or [OpenNext](https://opennext.js.org)?<br/>\nA: cdk-nextjs builds on Next.js's official [Deployment Adapter](https://nextjs.org/docs/app/guides/deployment-adapters) API and runs requests through [`@next/routing`](https://www.npmjs.com/package/@next/routing), the routing library Next.js publishes for platform adapters. Next.js tells cdk-nextjs what it built, and routing follows the same rules as `next start`. Nothing re-implements Next.js's router or patches its server. The few Next.js internals cdk-nextjs does load (the image optimizer and static file server) are loaded as they are, not modified. This keeps upgrades cheap and breaking changes rare. cdk-nextjs is tested against Next.js's own end-to-end test suite; [harness-coverage.md](docs/harness-coverage.md) lists the cases that differ and why.\n\nQ: Why does cdk-nextjs depend upon Next.js v16.3 or higher?\nA: cdk-nextjs builds through the public [Adapter API](https://nextjs.org/docs/app/api-reference/config/next-config-js/adapterPath), and 16.3 is the first version whose build output carries everything it reads (middleware matchers and per-file asset hashes). 16.2 also added the [Image Optimization Caching](https://nextjs.org/docs/app/api-reference/config/next-config-js/incrementalCacheHandlerPath#image-optimization-caching) it relies on. The runtime bundles `@next/routing` at the version it was tested against (see `package.json`), and newer Next.js 16 releases are expected to work.\n\nQ: How does cdk-nextjs support caching in Next.js?<br/>\nA: See [Caching Guide](./docs/caching-guide.md)\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: How can I `cdk bootstrap --cloudformation-execution-policies ...` my AWS Account with limited permissions for cdk-nextjs to deploy?<br />\nA: 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.\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 [OpenNext](https://opennext.js.org).\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"
9036
9036
  },
9037
9037
  "repository": {
9038
9038
  "type": "git",
@@ -9059,7 +9059,7 @@
9059
9059
  },
9060
9060
  "locationInModule": {
9061
9061
  "filename": "src/nextjs-api.ts",
9062
- "line": 195
9062
+ "line": 204
9063
9063
  },
9064
9064
  "parameters": [
9065
9065
  {
@@ -9085,7 +9085,7 @@
9085
9085
  "kind": "class",
9086
9086
  "locationInModule": {
9087
9087
  "filename": "src/nextjs-api.ts",
9088
- "line": 140
9088
+ "line": 149
9089
9089
  },
9090
9090
  "name": "NextjsApi",
9091
9091
  "properties": [
@@ -9097,7 +9097,7 @@
9097
9097
  "immutable": true,
9098
9098
  "locationInModule": {
9099
9099
  "filename": "src/nextjs-api.ts",
9100
- "line": 144
9100
+ "line": 153
9101
9101
  },
9102
9102
  "name": "api",
9103
9103
  "type": {
@@ -9113,7 +9113,7 @@
9113
9113
  "immutable": true,
9114
9114
  "locationInModule": {
9115
9115
  "filename": "src/nextjs-api.ts",
9116
- "line": 155
9116
+ "line": 164
9117
9117
  },
9118
9118
  "name": "url",
9119
9119
  "type": {
@@ -9129,7 +9129,7 @@
9129
9129
  "immutable": true,
9130
9130
  "locationInModule": {
9131
9131
  "filename": "src/nextjs-api.ts",
9132
- "line": 175
9132
+ "line": 184
9133
9133
  },
9134
9134
  "name": "redeployFunction",
9135
9135
  "optional": true,
@@ -9145,7 +9145,7 @@
9145
9145
  "immutable": true,
9146
9146
  "locationInModule": {
9147
9147
  "filename": "src/nextjs-api.ts",
9148
- "line": 180
9148
+ "line": 189
9149
9149
  },
9150
9150
  "name": "redeployRule",
9151
9151
  "optional": true,
@@ -9167,7 +9167,7 @@
9167
9167
  "kind": "interface",
9168
9168
  "locationInModule": {
9169
9169
  "filename": "src/nextjs-api.ts",
9170
- "line": 132
9170
+ "line": 141
9171
9171
  },
9172
9172
  "name": "NextjsApiFunctionGroup",
9173
9173
  "properties": [
@@ -9179,7 +9179,7 @@
9179
9179
  "immutable": true,
9180
9180
  "locationInModule": {
9181
9181
  "filename": "src/nextjs-api.ts",
9182
- "line": 134
9182
+ "line": 143
9183
9183
  },
9184
9184
  "name": "function",
9185
9185
  "type": {
@@ -9194,7 +9194,7 @@
9194
9194
  "immutable": true,
9195
9195
  "locationInModule": {
9196
9196
  "filename": "src/nextjs-api.ts",
9197
- "line": 133
9197
+ "line": 142
9198
9198
  },
9199
9199
  "name": "name",
9200
9200
  "type": {
@@ -9381,7 +9381,7 @@
9381
9381
  "immutable": true,
9382
9382
  "locationInModule": {
9383
9383
  "filename": "src/nextjs-api.ts",
9384
- "line": 112
9384
+ "line": 121
9385
9385
  },
9386
9386
  "name": "functionGroupBehaviors",
9387
9387
  "optional": true,
@@ -9404,7 +9404,7 @@
9404
9404
  "immutable": true,
9405
9405
  "locationInModule": {
9406
9406
  "filename": "src/nextjs-api.ts",
9407
- "line": 105
9407
+ "line": 114
9408
9408
  },
9409
9409
  "name": "functionGroups",
9410
9410
  "optional": true,
@@ -9445,7 +9445,7 @@
9445
9445
  "immutable": true,
9446
9446
  "locationInModule": {
9447
9447
  "filename": "src/nextjs-api.ts",
9448
- "line": 128
9448
+ "line": 137
9449
9449
  },
9450
9450
  "name": "redeployAfterUpdate",
9451
9451
  "optional": true,
@@ -9471,6 +9471,24 @@
9471
9471
  "fqn": "aws-cdk-lib.aws_lambda.IFunction"
9472
9472
  }
9473
9473
  },
9474
+ {
9475
+ "abstract": true,
9476
+ "docs": {
9477
+ "default": "- no resource; the build has no service worker",
9478
+ "stability": "stable",
9479
+ "summary": "The `Service-Worker-Allowed` header for `_next/static/service-worker/*`, which Next.js sends so a compiled service worker can register at a scope wider than its own directory, such as `/`. S3 can't send an arbitrary header, so setting this adds a resource for those files whose integration response does. Next.js uses the app's `basePath`, or `/` for none."
9480
+ },
9481
+ "immutable": true,
9482
+ "locationInModule": {
9483
+ "filename": "src/nextjs-api.ts",
9484
+ "line": 104
9485
+ },
9486
+ "name": "serviceWorkerAllowed",
9487
+ "optional": true,
9488
+ "type": {
9489
+ "primitive": "string"
9490
+ }
9491
+ },
9474
9492
  {
9475
9493
  "abstract": true,
9476
9494
  "docs": {
@@ -9499,7 +9517,7 @@
9499
9517
  "immutable": true,
9500
9518
  "locationInModule": {
9501
9519
  "filename": "src/nextjs-api.ts",
9502
- "line": 99
9520
+ "line": 108
9503
9521
  },
9504
9522
  "name": "vpc",
9505
9523
  "optional": true,
@@ -9584,7 +9602,7 @@
9584
9602
  },
9585
9603
  "locationInModule": {
9586
9604
  "filename": "src/root-constructs/nextjs-base-construct.ts",
9587
- "line": 460
9605
+ "line": 473
9588
9606
  },
9589
9607
  "name": "createNextjsFunctions",
9590
9608
  "protected": true,
@@ -9752,6 +9770,24 @@
9752
9770
  "primitive": "string"
9753
9771
  }
9754
9772
  },
9773
+ {
9774
+ "docs": {
9775
+ "remarks": "The app's own\n`basePath`, as `next build` uses, not `resolvedBasePath`: it is the URL\nscope the browser checks.",
9776
+ "stability": "stable",
9777
+ "summary": "The `Service-Worker-Allowed` value for `_next/static/service-worker/*`, or `undefined` when the build has no service worker."
9778
+ },
9779
+ "immutable": true,
9780
+ "locationInModule": {
9781
+ "filename": "src/root-constructs/nextjs-base-construct.ts",
9782
+ "line": 423
9783
+ },
9784
+ "name": "serviceWorkerAllowed",
9785
+ "optional": true,
9786
+ "protected": true,
9787
+ "type": {
9788
+ "primitive": "string"
9789
+ }
9790
+ },
9755
9791
  {
9756
9792
  "docs": {
9757
9793
  "stability": "stable"
@@ -11311,7 +11347,7 @@
11311
11347
  },
11312
11348
  "locationInModule": {
11313
11349
  "filename": "src/nextjs-distribution.ts",
11314
- "line": 209
11350
+ "line": 269
11315
11351
  },
11316
11352
  "parameters": [
11317
11353
  {
@@ -11337,7 +11373,7 @@
11337
11373
  "kind": "class",
11338
11374
  "locationInModule": {
11339
11375
  "filename": "src/nextjs-distribution.ts",
11340
- "line": 159
11376
+ "line": 207
11341
11377
  },
11342
11378
  "name": "NextjsDistribution",
11343
11379
  "properties": [
@@ -11347,7 +11383,7 @@
11347
11383
  },
11348
11384
  "locationInModule": {
11349
11385
  "filename": "src/nextjs-distribution.ts",
11350
- "line": 160
11386
+ "line": 208
11351
11387
  },
11352
11388
  "name": "distribution",
11353
11389
  "type": {
@@ -11368,7 +11404,7 @@
11368
11404
  "kind": "interface",
11369
11405
  "locationInModule": {
11370
11406
  "filename": "src/nextjs-distribution.ts",
11371
- "line": 153
11407
+ "line": 201
11372
11408
  },
11373
11409
  "name": "NextjsDistributionFunctionGroup",
11374
11410
  "properties": [
@@ -11381,7 +11417,7 @@
11381
11417
  "immutable": true,
11382
11418
  "locationInModule": {
11383
11419
  "filename": "src/nextjs-distribution.ts",
11384
- "line": 156
11420
+ "line": 204
11385
11421
  },
11386
11422
  "name": "functionUrl",
11387
11423
  "type": {
@@ -11396,7 +11432,7 @@
11396
11432
  "immutable": true,
11397
11433
  "locationInModule": {
11398
11434
  "filename": "src/nextjs-distribution.ts",
11399
- "line": 154
11435
+ "line": 202
11400
11436
  },
11401
11437
  "name": "name",
11402
11438
  "type": {
@@ -11416,7 +11452,7 @@
11416
11452
  "kind": "interface",
11417
11453
  "locationInModule": {
11418
11454
  "filename": "src/nextjs-distribution.ts",
11419
- "line": 57
11455
+ "line": 68
11420
11456
  },
11421
11457
  "name": "NextjsDistributionOverrides",
11422
11458
  "properties": [
@@ -11428,7 +11464,7 @@
11428
11464
  "immutable": true,
11429
11465
  "locationInModule": {
11430
11466
  "filename": "src/nextjs-distribution.ts",
11431
- "line": 58
11467
+ "line": 69
11432
11468
  },
11433
11469
  "name": "distributionProps",
11434
11470
  "optional": true,
@@ -11444,7 +11480,7 @@
11444
11480
  "immutable": true,
11445
11481
  "locationInModule": {
11446
11482
  "filename": "src/nextjs-distribution.ts",
11447
- "line": 62
11483
+ "line": 73
11448
11484
  },
11449
11485
  "name": "dynamicBehaviorOptions",
11450
11486
  "optional": true,
@@ -11460,7 +11496,7 @@
11460
11496
  "immutable": true,
11461
11497
  "locationInModule": {
11462
11498
  "filename": "src/nextjs-distribution.ts",
11463
- "line": 63
11499
+ "line": 74
11464
11500
  },
11465
11501
  "name": "dynamicCachePolicyProps",
11466
11502
  "optional": true,
@@ -11476,7 +11512,7 @@
11476
11512
  "immutable": true,
11477
11513
  "locationInModule": {
11478
11514
  "filename": "src/nextjs-distribution.ts",
11479
- "line": 65
11515
+ "line": 76
11480
11516
  },
11481
11517
  "name": "dynamicFunctionUrlOriginWithOACProps",
11482
11518
  "optional": true,
@@ -11492,7 +11528,7 @@
11492
11528
  "immutable": true,
11493
11529
  "locationInModule": {
11494
11530
  "filename": "src/nextjs-distribution.ts",
11495
- "line": 64
11531
+ "line": 75
11496
11532
  },
11497
11533
  "name": "dynamicResponseHeadersPolicyProps",
11498
11534
  "optional": true,
@@ -11508,7 +11544,7 @@
11508
11544
  "immutable": true,
11509
11545
  "locationInModule": {
11510
11546
  "filename": "src/nextjs-distribution.ts",
11511
- "line": 66
11547
+ "line": 77
11512
11548
  },
11513
11549
  "name": "dynamicVpcOriginWithEndpointProps",
11514
11550
  "optional": true,
@@ -11524,7 +11560,7 @@
11524
11560
  "immutable": true,
11525
11561
  "locationInModule": {
11526
11562
  "filename": "src/nextjs-distribution.ts",
11527
- "line": 59
11563
+ "line": 70
11528
11564
  },
11529
11565
  "name": "imageBehaviorOptions",
11530
11566
  "optional": true,
@@ -11540,7 +11576,7 @@
11540
11576
  "immutable": true,
11541
11577
  "locationInModule": {
11542
11578
  "filename": "src/nextjs-distribution.ts",
11543
- "line": 60
11579
+ "line": 71
11544
11580
  },
11545
11581
  "name": "imageCachePolicyProps",
11546
11582
  "optional": true,
@@ -11556,7 +11592,7 @@
11556
11592
  "immutable": true,
11557
11593
  "locationInModule": {
11558
11594
  "filename": "src/nextjs-distribution.ts",
11559
- "line": 61
11595
+ "line": 72
11560
11596
  },
11561
11597
  "name": "imageResponseHeadersPolicyProps",
11562
11598
  "optional": true,
@@ -11572,7 +11608,7 @@
11572
11608
  "immutable": true,
11573
11609
  "locationInModule": {
11574
11610
  "filename": "src/nextjs-distribution.ts",
11575
- "line": 69
11611
+ "line": 80
11576
11612
  },
11577
11613
  "name": "s3BucketOriginProps",
11578
11614
  "optional": true,
@@ -11588,7 +11624,7 @@
11588
11624
  "immutable": true,
11589
11625
  "locationInModule": {
11590
11626
  "filename": "src/nextjs-distribution.ts",
11591
- "line": 67
11627
+ "line": 78
11592
11628
  },
11593
11629
  "name": "staticBehaviorOptions",
11594
11630
  "optional": true,
@@ -11604,7 +11640,7 @@
11604
11640
  "immutable": true,
11605
11641
  "locationInModule": {
11606
11642
  "filename": "src/nextjs-distribution.ts",
11607
- "line": 68
11643
+ "line": 79
11608
11644
  },
11609
11645
  "name": "staticResponseHeadersPolicyProps",
11610
11646
  "optional": true,
@@ -11625,7 +11661,7 @@
11625
11661
  "kind": "interface",
11626
11662
  "locationInModule": {
11627
11663
  "filename": "src/nextjs-distribution.ts",
11628
- "line": 72
11664
+ "line": 83
11629
11665
  },
11630
11666
  "name": "NextjsDistributionProps",
11631
11667
  "properties": [
@@ -11639,7 +11675,7 @@
11639
11675
  "immutable": true,
11640
11676
  "locationInModule": {
11641
11677
  "filename": "src/nextjs-distribution.ts",
11642
- "line": 77
11678
+ "line": 88
11643
11679
  },
11644
11680
  "name": "assetsBucket",
11645
11681
  "type": {
@@ -11654,7 +11690,7 @@
11654
11690
  "immutable": true,
11655
11691
  "locationInModule": {
11656
11692
  "filename": "src/nextjs-distribution.ts",
11657
- "line": 115
11693
+ "line": 126
11658
11694
  },
11659
11695
  "name": "nextjsType",
11660
11696
  "type": {
@@ -11670,7 +11706,7 @@
11670
11706
  "immutable": true,
11671
11707
  "locationInModule": {
11672
11708
  "filename": "src/nextjs-distribution.ts",
11673
- "line": 124
11709
+ "line": 135
11674
11710
  },
11675
11711
  "name": "publicDirEntries",
11676
11712
  "type": {
@@ -11693,7 +11729,7 @@
11693
11729
  "immutable": true,
11694
11730
  "locationInModule": {
11695
11731
  "filename": "src/nextjs-distribution.ts",
11696
- "line": 96
11732
+ "line": 107
11697
11733
  },
11698
11734
  "name": "assetPrefix",
11699
11735
  "optional": true,
@@ -11711,7 +11747,7 @@
11711
11747
  "immutable": true,
11712
11748
  "locationInModule": {
11713
11749
  "filename": "src/nextjs-distribution.ts",
11714
- "line": 101
11750
+ "line": 112
11715
11751
  },
11716
11752
  "name": "basePath",
11717
11753
  "optional": true,
@@ -11728,7 +11764,7 @@
11728
11764
  "immutable": true,
11729
11765
  "locationInModule": {
11730
11766
  "filename": "src/nextjs-distribution.ts",
11731
- "line": 105
11767
+ "line": 116
11732
11768
  },
11733
11769
  "name": "certificate",
11734
11770
  "optional": true,
@@ -11744,7 +11780,7 @@
11744
11780
  "immutable": true,
11745
11781
  "locationInModule": {
11746
11782
  "filename": "src/nextjs-distribution.ts",
11747
- "line": 106
11783
+ "line": 117
11748
11784
  },
11749
11785
  "name": "distribution",
11750
11786
  "optional": true,
@@ -11762,7 +11798,7 @@
11762
11798
  "immutable": true,
11763
11799
  "locationInModule": {
11764
11800
  "filename": "src/nextjs-distribution.ts",
11765
- "line": 137
11801
+ "line": 157
11766
11802
  },
11767
11803
  "name": "functionGroupBehaviors",
11768
11804
  "optional": true,
@@ -11785,7 +11821,7 @@
11785
11821
  "immutable": true,
11786
11822
  "locationInModule": {
11787
11823
  "filename": "src/nextjs-distribution.ts",
11788
- "line": 130
11824
+ "line": 150
11789
11825
  },
11790
11826
  "name": "functionGroups",
11791
11827
  "optional": true,
@@ -11807,7 +11843,7 @@
11807
11843
  "immutable": true,
11808
11844
  "locationInModule": {
11809
11845
  "filename": "src/nextjs-distribution.ts",
11810
- "line": 110
11846
+ "line": 121
11811
11847
  },
11812
11848
  "name": "functionUrl",
11813
11849
  "optional": true,
@@ -11824,7 +11860,7 @@
11824
11860
  "immutable": true,
11825
11861
  "locationInModule": {
11826
11862
  "filename": "src/nextjs-distribution.ts",
11827
- "line": 114
11863
+ "line": 125
11828
11864
  },
11829
11865
  "name": "loadBalancer",
11830
11866
  "optional": true,
@@ -11844,7 +11880,7 @@
11844
11880
  "immutable": true,
11845
11881
  "locationInModule": {
11846
11882
  "filename": "src/nextjs-distribution.ts",
11847
- "line": 149
11883
+ "line": 169
11848
11884
  },
11849
11885
  "name": "maxCacheBehaviors",
11850
11886
  "optional": true,
@@ -11861,13 +11897,71 @@
11861
11897
  "immutable": true,
11862
11898
  "locationInModule": {
11863
11899
  "filename": "src/nextjs-distribution.ts",
11864
- "line": 119
11900
+ "line": 130
11865
11901
  },
11866
11902
  "name": "overrides",
11867
11903
  "optional": true,
11868
11904
  "type": {
11869
11905
  "fqn": "cdk-nextjs.NextjsDistributionOverrides"
11870
11906
  }
11907
+ },
11908
+ {
11909
+ "abstract": true,
11910
+ "docs": {
11911
+ "default": "- no behavior; the build has no service worker",
11912
+ "stability": "stable",
11913
+ "summary": "The `Service-Worker-Allowed` header for `_next/static/service-worker/*`, which Next.js sends so a compiled service worker can register at a scope wider than its own directory, such as `/`. S3 can't send an arbitrary header, so setting this adds a behavior for those files whose response headers policy does. Next.js uses the app's `basePath`, or `/` for none."
11914
+ },
11915
+ "immutable": true,
11916
+ "locationInModule": {
11917
+ "filename": "src/nextjs-distribution.ts",
11918
+ "line": 144
11919
+ },
11920
+ "name": "serviceWorkerAllowed",
11921
+ "optional": true,
11922
+ "type": {
11923
+ "primitive": "string"
11924
+ }
11925
+ },
11926
+ {
11927
+ "abstract": true,
11928
+ "docs": {
11929
+ "default": "- none",
11930
+ "remarks": "It must define `viewerRequest(event)` (a function, sync or async, or a\n`var`/`let`/`const`): return a response to answer the viewer, or the\nrequest (or nothing) to carry on. It is spliced into cdk-nextjs's own\nviewer-request functions, ahead of their logic, so it may not use the\nname `handler`, and the combined function must fit CloudFront's 10 KB.\nIt runs on `cloudfront-js-2.0`, so it may be async and read\n{@link viewerRequestKeyValueStore} with `cf.kvs()`. A bring-your-own\n{@link distribution}'s default behavior isn't covered.",
11931
+ "see": "https://github.com/cdklabs/cdk-nextjs#running-code-on-every-viewer-request",
11932
+ "stability": "stable",
11933
+ "summary": "CloudFront Function code run first on every viewer request, on every behavior cdk-nextjs adds, static assets included — HTTP Basic auth on a pre-launch site, geo-gating."
11934
+ },
11935
+ "immutable": true,
11936
+ "locationInModule": {
11937
+ "filename": "src/nextjs-distribution.ts",
11938
+ "line": 187
11939
+ },
11940
+ "name": "viewerRequestFunctionCode",
11941
+ "optional": true,
11942
+ "type": {
11943
+ "fqn": "aws-cdk-lib.aws_cloudfront.FunctionCode"
11944
+ }
11945
+ },
11946
+ {
11947
+ "abstract": true,
11948
+ "docs": {
11949
+ "default": "- none",
11950
+ "remarks": "Read it with `cf.kvs()`, no ID needed.",
11951
+ "see": "https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-custom-methods.html",
11952
+ "stability": "stable",
11953
+ "summary": "A CloudFront KeyValueStore associated with every viewer-request function {@link viewerRequestFunctionCode} is copied into (up to three, one per kind of behavior), so values it reads — Basic auth credentials, an allowlist — live outside the CloudFormation template and change without a deploy."
11954
+ },
11955
+ "immutable": true,
11956
+ "locationInModule": {
11957
+ "filename": "src/nextjs-distribution.ts",
11958
+ "line": 197
11959
+ },
11960
+ "name": "viewerRequestKeyValueStore",
11961
+ "optional": true,
11962
+ "type": {
11963
+ "fqn": "aws-cdk-lib.aws_cloudfront.IKeyValueStore"
11964
+ }
11871
11965
  }
11872
11966
  ],
11873
11967
  "symbolId": "src/nextjs-distribution:NextjsDistributionProps"
@@ -12423,7 +12517,7 @@
12423
12517
  },
12424
12518
  "locationInModule": {
12425
12519
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12426
- "line": 106
12520
+ "line": 125
12427
12521
  },
12428
12522
  "parameters": [
12429
12523
  {
@@ -12449,7 +12543,7 @@
12449
12543
  "kind": "class",
12450
12544
  "locationInModule": {
12451
12545
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12452
- "line": 88
12546
+ "line": 107
12453
12547
  },
12454
12548
  "name": "NextjsGlobalContainers",
12455
12549
  "properties": [
@@ -12461,7 +12555,7 @@
12461
12555
  "immutable": true,
12462
12556
  "locationInModule": {
12463
12557
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12464
- "line": 97
12558
+ "line": 116
12465
12559
  },
12466
12560
  "name": "url",
12467
12561
  "overrides": "cdk-nextjs.NextjsBaseConstruct",
@@ -12475,7 +12569,7 @@
12475
12569
  },
12476
12570
  "locationInModule": {
12477
12571
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12478
- "line": 89
12572
+ "line": 108
12479
12573
  },
12480
12574
  "name": "nextjsContainers",
12481
12575
  "type": {
@@ -12488,7 +12582,7 @@
12488
12582
  },
12489
12583
  "locationInModule": {
12490
12584
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12491
- "line": 90
12585
+ "line": 109
12492
12586
  },
12493
12587
  "name": "nextjsDistribution",
12494
12588
  "type": {
@@ -12501,7 +12595,7 @@
12501
12595
  },
12502
12596
  "locationInModule": {
12503
12597
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12504
- "line": 91
12598
+ "line": 110
12505
12599
  },
12506
12600
  "name": "nextjsPostDeploy",
12507
12601
  "type": {
@@ -12524,7 +12618,7 @@
12524
12618
  "kind": "interface",
12525
12619
  "locationInModule": {
12526
12620
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12527
- "line": 25
12621
+ "line": 29
12528
12622
  },
12529
12623
  "name": "NextjsGlobalContainersConstructOverrides",
12530
12624
  "properties": [
@@ -12536,7 +12630,7 @@
12536
12630
  "immutable": true,
12537
12631
  "locationInModule": {
12538
12632
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12539
- "line": 26
12633
+ "line": 30
12540
12634
  },
12541
12635
  "name": "nextjsContainersProps",
12542
12636
  "optional": true,
@@ -12552,7 +12646,7 @@
12552
12646
  "immutable": true,
12553
12647
  "locationInModule": {
12554
12648
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12555
- "line": 27
12649
+ "line": 31
12556
12650
  },
12557
12651
  "name": "nextjsDistributionProps",
12558
12652
  "optional": true,
@@ -12578,7 +12672,7 @@
12578
12672
  "kind": "interface",
12579
12673
  "locationInModule": {
12580
12674
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12581
- "line": 35
12675
+ "line": 39
12582
12676
  },
12583
12677
  "name": "NextjsGlobalContainersOverrides",
12584
12678
  "properties": [
@@ -12590,7 +12684,7 @@
12590
12684
  "immutable": true,
12591
12685
  "locationInModule": {
12592
12686
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12593
- "line": 37
12687
+ "line": 41
12594
12688
  },
12595
12689
  "name": "nextjsContainers",
12596
12690
  "optional": true,
@@ -12606,7 +12700,7 @@
12606
12700
  "immutable": true,
12607
12701
  "locationInModule": {
12608
12702
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12609
- "line": 38
12703
+ "line": 42
12610
12704
  },
12611
12705
  "name": "nextjsDistribution",
12612
12706
  "optional": true,
@@ -12622,7 +12716,7 @@
12622
12716
  "immutable": true,
12623
12717
  "locationInModule": {
12624
12718
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12625
- "line": 36
12719
+ "line": 40
12626
12720
  },
12627
12721
  "name": "nextjsGlobalContainers",
12628
12722
  "optional": true,
@@ -12646,7 +12740,7 @@
12646
12740
  "kind": "interface",
12647
12741
  "locationInModule": {
12648
12742
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12649
- "line": 41
12743
+ "line": 45
12650
12744
  },
12651
12745
  "name": "NextjsGlobalContainersProps",
12652
12746
  "properties": [
@@ -12661,7 +12755,7 @@
12661
12755
  "immutable": true,
12662
12756
  "locationInModule": {
12663
12757
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12664
- "line": 75
12758
+ "line": 79
12665
12759
  },
12666
12760
  "name": "healthCheckPath",
12667
12761
  "type": {
@@ -12678,7 +12772,7 @@
12678
12772
  "immutable": true,
12679
12773
  "locationInModule": {
12680
12774
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12681
- "line": 48
12775
+ "line": 52
12682
12776
  },
12683
12777
  "name": "alb",
12684
12778
  "optional": true,
@@ -12696,7 +12790,7 @@
12696
12790
  "immutable": true,
12697
12791
  "locationInModule": {
12698
12792
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12699
- "line": 53
12793
+ "line": 57
12700
12794
  },
12701
12795
  "name": "distribution",
12702
12796
  "optional": true,
@@ -12714,7 +12808,7 @@
12714
12808
  "immutable": true,
12715
12809
  "locationInModule": {
12716
12810
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12717
- "line": 58
12811
+ "line": 62
12718
12812
  },
12719
12813
  "name": "ecsCluster",
12720
12814
  "optional": true,
@@ -12731,13 +12825,52 @@
12731
12825
  "immutable": true,
12732
12826
  "locationInModule": {
12733
12827
  "filename": "src/root-constructs/nextjs-global-containers.ts",
12734
- "line": 79
12828
+ "line": 83
12735
12829
  },
12736
12830
  "name": "overrides",
12737
12831
  "optional": true,
12738
12832
  "type": {
12739
12833
  "fqn": "cdk-nextjs.NextjsGlobalContainersOverrides"
12740
12834
  }
12835
+ },
12836
+ {
12837
+ "abstract": true,
12838
+ "docs": {
12839
+ "default": "- none",
12840
+ "remarks": "It must define\n`viewerRequest(event)`, as a function or a `var`/`let`/`const`.",
12841
+ "see": "NextjsDistributionProps.viewerRequestFunctionCode *",
12842
+ "stability": "stable",
12843
+ "summary": "CloudFront Function code run first on every viewer request, static assets included — HTTP Basic auth on a pre-launch site, say."
12844
+ },
12845
+ "immutable": true,
12846
+ "locationInModule": {
12847
+ "filename": "src/root-constructs/nextjs-global-containers.ts",
12848
+ "line": 91
12849
+ },
12850
+ "name": "viewerRequestFunctionCode",
12851
+ "optional": true,
12852
+ "type": {
12853
+ "fqn": "aws-cdk-lib.aws_cloudfront.FunctionCode"
12854
+ }
12855
+ },
12856
+ {
12857
+ "abstract": true,
12858
+ "docs": {
12859
+ "default": "- none",
12860
+ "see": "NextjsDistributionProps.viewerRequestKeyValueStore *",
12861
+ "stability": "stable",
12862
+ "summary": "A CloudFront KeyValueStore `viewerRequestFunctionCode` can read with `cf.kvs()`, so credentials stay out of the template."
12863
+ },
12864
+ "immutable": true,
12865
+ "locationInModule": {
12866
+ "filename": "src/root-constructs/nextjs-global-containers.ts",
12867
+ "line": 98
12868
+ },
12869
+ "name": "viewerRequestKeyValueStore",
12870
+ "optional": true,
12871
+ "type": {
12872
+ "fqn": "aws-cdk-lib.aws_cloudfront.IKeyValueStore"
12873
+ }
12741
12874
  }
12742
12875
  ],
12743
12876
  "symbolId": "src/root-constructs/nextjs-global-containers:NextjsGlobalContainersProps"
@@ -12756,7 +12889,7 @@
12756
12889
  },
12757
12890
  "locationInModule": {
12758
12891
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12759
- "line": 92
12892
+ "line": 111
12760
12893
  },
12761
12894
  "parameters": [
12762
12895
  {
@@ -12782,7 +12915,7 @@
12782
12915
  "kind": "class",
12783
12916
  "locationInModule": {
12784
12917
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12785
- "line": 74
12918
+ "line": 93
12786
12919
  },
12787
12920
  "name": "NextjsGlobalFunctions",
12788
12921
  "properties": [
@@ -12794,7 +12927,7 @@
12794
12927
  "immutable": true,
12795
12928
  "locationInModule": {
12796
12929
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12797
- "line": 83
12930
+ "line": 102
12798
12931
  },
12799
12932
  "name": "url",
12800
12933
  "overrides": "cdk-nextjs.NextjsBaseConstruct",
@@ -12808,7 +12941,7 @@
12808
12941
  },
12809
12942
  "locationInModule": {
12810
12943
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12811
- "line": 76
12944
+ "line": 95
12812
12945
  },
12813
12946
  "name": "nextjsDistribution",
12814
12947
  "type": {
@@ -12821,7 +12954,7 @@
12821
12954
  },
12822
12955
  "locationInModule": {
12823
12956
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12824
- "line": 75
12957
+ "line": 94
12825
12958
  },
12826
12959
  "name": "nextjsFunctions",
12827
12960
  "type": {
@@ -12834,7 +12967,7 @@
12834
12967
  },
12835
12968
  "locationInModule": {
12836
12969
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12837
- "line": 77
12970
+ "line": 96
12838
12971
  },
12839
12972
  "name": "nextjsPostDeploy",
12840
12973
  "type": {
@@ -12857,7 +12990,7 @@
12857
12990
  "kind": "interface",
12858
12991
  "locationInModule": {
12859
12992
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12860
- "line": 28
12993
+ "line": 32
12861
12994
  },
12862
12995
  "name": "NextjsGlobalFunctionsConstructOverrides",
12863
12996
  "properties": [
@@ -12869,7 +13002,7 @@
12869
13002
  "immutable": true,
12870
13003
  "locationInModule": {
12871
13004
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12872
- "line": 29
13005
+ "line": 33
12873
13006
  },
12874
13007
  "name": "nextjsDistributionProps",
12875
13008
  "optional": true,
@@ -12895,7 +13028,7 @@
12895
13028
  "kind": "interface",
12896
13029
  "locationInModule": {
12897
13030
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12898
- "line": 37
13031
+ "line": 41
12899
13032
  },
12900
13033
  "name": "NextjsGlobalFunctionsOverrides",
12901
13034
  "properties": [
@@ -12907,7 +13040,7 @@
12907
13040
  "immutable": true,
12908
13041
  "locationInModule": {
12909
13042
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12910
- "line": 40
13043
+ "line": 44
12911
13044
  },
12912
13045
  "name": "nextjsDistribution",
12913
13046
  "optional": true,
@@ -12923,7 +13056,7 @@
12923
13056
  "immutable": true,
12924
13057
  "locationInModule": {
12925
13058
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12926
- "line": 39
13059
+ "line": 43
12927
13060
  },
12928
13061
  "name": "nextjsFunctions",
12929
13062
  "optional": true,
@@ -12939,7 +13072,7 @@
12939
13072
  "immutable": true,
12940
13073
  "locationInModule": {
12941
13074
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12942
- "line": 38
13075
+ "line": 42
12943
13076
  },
12944
13077
  "name": "nextjsGlobalFunctions",
12945
13078
  "optional": true,
@@ -12963,7 +13096,7 @@
12963
13096
  "kind": "interface",
12964
13097
  "locationInModule": {
12965
13098
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12966
- "line": 43
13099
+ "line": 47
12967
13100
  },
12968
13101
  "name": "NextjsGlobalFunctionsProps",
12969
13102
  "properties": [
@@ -12977,7 +13110,7 @@
12977
13110
  "immutable": true,
12978
13111
  "locationInModule": {
12979
13112
  "filename": "src/root-constructs/nextjs-global-functions.ts",
12980
- "line": 48
13113
+ "line": 52
12981
13114
  },
12982
13115
  "name": "distribution",
12983
13116
  "optional": true,
@@ -12997,7 +13130,7 @@
12997
13130
  "immutable": true,
12998
13131
  "locationInModule": {
12999
13132
  "filename": "src/root-constructs/nextjs-global-functions.ts",
13000
- "line": 61
13133
+ "line": 65
13001
13134
  },
13002
13135
  "name": "functionGroups",
13003
13136
  "optional": true,
@@ -13019,13 +13152,52 @@
13019
13152
  "immutable": true,
13020
13153
  "locationInModule": {
13021
13154
  "filename": "src/root-constructs/nextjs-global-functions.ts",
13022
- "line": 65
13155
+ "line": 69
13023
13156
  },
13024
13157
  "name": "overrides",
13025
13158
  "optional": true,
13026
13159
  "type": {
13027
13160
  "fqn": "cdk-nextjs.NextjsGlobalFunctionsOverrides"
13028
13161
  }
13162
+ },
13163
+ {
13164
+ "abstract": true,
13165
+ "docs": {
13166
+ "default": "- none",
13167
+ "remarks": "It must define\n`viewerRequest(event)`, as a function or a `var`/`let`/`const`.",
13168
+ "see": "NextjsDistributionProps.viewerRequestFunctionCode *",
13169
+ "stability": "stable",
13170
+ "summary": "CloudFront Function code run first on every viewer request, static assets included — HTTP Basic auth on a pre-launch site, say."
13171
+ },
13172
+ "immutable": true,
13173
+ "locationInModule": {
13174
+ "filename": "src/root-constructs/nextjs-global-functions.ts",
13175
+ "line": 77
13176
+ },
13177
+ "name": "viewerRequestFunctionCode",
13178
+ "optional": true,
13179
+ "type": {
13180
+ "fqn": "aws-cdk-lib.aws_cloudfront.FunctionCode"
13181
+ }
13182
+ },
13183
+ {
13184
+ "abstract": true,
13185
+ "docs": {
13186
+ "default": "- none",
13187
+ "see": "NextjsDistributionProps.viewerRequestKeyValueStore *",
13188
+ "stability": "stable",
13189
+ "summary": "A CloudFront KeyValueStore `viewerRequestFunctionCode` can read with `cf.kvs()`, so credentials stay out of the template."
13190
+ },
13191
+ "immutable": true,
13192
+ "locationInModule": {
13193
+ "filename": "src/root-constructs/nextjs-global-functions.ts",
13194
+ "line": 84
13195
+ },
13196
+ "name": "viewerRequestKeyValueStore",
13197
+ "optional": true,
13198
+ "type": {
13199
+ "fqn": "aws-cdk-lib.aws_cloudfront.IKeyValueStore"
13200
+ }
13029
13201
  }
13030
13202
  ],
13031
13203
  "symbolId": "src/root-constructs/nextjs-global-functions:NextjsGlobalFunctionsProps"
@@ -18017,7 +18189,7 @@
18017
18189
  "immutable": true,
18018
18190
  "locationInModule": {
18019
18191
  "filename": "src/generated-structs/OptionalNextjsApiProps.ts",
18020
- "line": 50
18192
+ "line": 56
18021
18193
  },
18022
18194
  "name": "basePath",
18023
18195
  "optional": true,
@@ -18034,7 +18206,7 @@
18034
18206
  "immutable": true,
18035
18207
  "locationInModule": {
18036
18208
  "filename": "src/generated-structs/OptionalNextjsApiProps.ts",
18037
- "line": 60
18209
+ "line": 66
18038
18210
  },
18039
18211
  "name": "publicDirEntries",
18040
18212
  "optional": true,
@@ -18058,7 +18230,7 @@
18058
18230
  "immutable": true,
18059
18231
  "locationInModule": {
18060
18232
  "filename": "src/generated-structs/OptionalNextjsApiProps.ts",
18061
- "line": 45
18233
+ "line": 51
18062
18234
  },
18063
18235
  "name": "redeployAfterUpdate",
18064
18236
  "optional": true,
@@ -18076,7 +18248,7 @@
18076
18248
  "immutable": true,
18077
18249
  "locationInModule": {
18078
18250
  "filename": "src/generated-structs/OptionalNextjsApiProps.ts",
18079
- "line": 30
18251
+ "line": 36
18080
18252
  },
18081
18253
  "name": "serverFunction",
18082
18254
  "optional": true,
@@ -18084,6 +18256,24 @@
18084
18256
  "fqn": "aws-cdk-lib.aws_lambda.IFunction"
18085
18257
  }
18086
18258
  },
18259
+ {
18260
+ "abstract": true,
18261
+ "docs": {
18262
+ "default": "- no resource; the build has no service worker",
18263
+ "stability": "stable",
18264
+ "summary": "The `Service-Worker-Allowed` header for `_next/static/service-worker/*`, which Next.js sends so a compiled service worker can register at a scope wider than its own directory, such as `/`. S3 can't send an arbitrary header, so setting this adds a resource for those files whose integration response does. Next.js uses the app's `basePath`, or `/` for none."
18265
+ },
18266
+ "immutable": true,
18267
+ "locationInModule": {
18268
+ "filename": "src/generated-structs/OptionalNextjsApiProps.ts",
18269
+ "line": 30
18270
+ },
18271
+ "name": "serviceWorkerAllowed",
18272
+ "optional": true,
18273
+ "type": {
18274
+ "primitive": "string"
18275
+ }
18276
+ },
18087
18277
  {
18088
18278
  "abstract": true,
18089
18279
  "docs": {
@@ -18093,7 +18283,7 @@
18093
18283
  "immutable": true,
18094
18284
  "locationInModule": {
18095
18285
  "filename": "src/generated-structs/OptionalNextjsApiProps.ts",
18096
- "line": 55
18286
+ "line": 61
18097
18287
  },
18098
18288
  "name": "staticAssetsBucket",
18099
18289
  "optional": true,
@@ -18558,7 +18748,7 @@
18558
18748
  "immutable": true,
18559
18749
  "locationInModule": {
18560
18750
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18561
- "line": 66
18751
+ "line": 93
18562
18752
  },
18563
18753
  "name": "assetPrefix",
18564
18754
  "optional": true,
@@ -18576,7 +18766,7 @@
18576
18766
  "immutable": true,
18577
18767
  "locationInModule": {
18578
18768
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18579
- "line": 81
18769
+ "line": 108
18580
18770
  },
18581
18771
  "name": "assetsBucket",
18582
18772
  "optional": true,
@@ -18594,7 +18784,7 @@
18594
18784
  "immutable": true,
18595
18785
  "locationInModule": {
18596
18786
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18597
- "line": 46
18787
+ "line": 73
18598
18788
  },
18599
18789
  "name": "basePath",
18600
18790
  "optional": true,
@@ -18611,7 +18801,7 @@
18611
18801
  "immutable": true,
18612
18802
  "locationInModule": {
18613
18803
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18614
- "line": 39
18804
+ "line": 66
18615
18805
  },
18616
18806
  "name": "certificate",
18617
18807
  "optional": true,
@@ -18627,7 +18817,7 @@
18627
18817
  "immutable": true,
18628
18818
  "locationInModule": {
18629
18819
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18630
- "line": 34
18820
+ "line": 61
18631
18821
  },
18632
18822
  "name": "distribution",
18633
18823
  "optional": true,
@@ -18644,7 +18834,7 @@
18644
18834
  "immutable": true,
18645
18835
  "locationInModule": {
18646
18836
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18647
- "line": 30
18837
+ "line": 57
18648
18838
  },
18649
18839
  "name": "functionUrl",
18650
18840
  "optional": true,
@@ -18661,7 +18851,7 @@
18661
18851
  "immutable": true,
18662
18852
  "locationInModule": {
18663
18853
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18664
- "line": 25
18854
+ "line": 52
18665
18855
  },
18666
18856
  "name": "loadBalancer",
18667
18857
  "optional": true,
@@ -18680,7 +18870,7 @@
18680
18870
  "immutable": true,
18681
18871
  "locationInModule": {
18682
18872
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18683
- "line": 20
18873
+ "line": 47
18684
18874
  },
18685
18875
  "name": "maxCacheBehaviors",
18686
18876
  "optional": true,
@@ -18696,7 +18886,7 @@
18696
18886
  "immutable": true,
18697
18887
  "locationInModule": {
18698
18888
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18699
- "line": 75
18889
+ "line": 102
18700
18890
  },
18701
18891
  "name": "nextjsType",
18702
18892
  "optional": true,
@@ -18713,7 +18903,7 @@
18713
18903
  "immutable": true,
18714
18904
  "locationInModule": {
18715
18905
  "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18716
- "line": 71
18906
+ "line": 98
18717
18907
  },
18718
18908
  "name": "publicDirEntries",
18719
18909
  "optional": true,
@@ -18725,6 +18915,62 @@
18725
18915
  "kind": "array"
18726
18916
  }
18727
18917
  }
18918
+ },
18919
+ {
18920
+ "abstract": true,
18921
+ "docs": {
18922
+ "default": "- no behavior; the build has no service worker",
18923
+ "stability": "stable",
18924
+ "summary": "The `Service-Worker-Allowed` header for `_next/static/service-worker/*`, which Next.js sends so a compiled service worker can register at a scope wider than its own directory, such as `/`. S3 can't send an arbitrary header, so setting this adds a behavior for those files whose response headers policy does. Next.js uses the app's `basePath`, or `/` for none."
18925
+ },
18926
+ "immutable": true,
18927
+ "locationInModule": {
18928
+ "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18929
+ "line": 35
18930
+ },
18931
+ "name": "serviceWorkerAllowed",
18932
+ "optional": true,
18933
+ "type": {
18934
+ "primitive": "string"
18935
+ }
18936
+ },
18937
+ {
18938
+ "abstract": true,
18939
+ "docs": {
18940
+ "default": "- none",
18941
+ "remarks": "It must define `viewerRequest(event)` (a function, sync or async, or a\n`var`/`let`/`const`): return a response to answer the viewer, or the\nrequest (or nothing) to carry on. It is spliced into cdk-nextjs's own\nviewer-request functions, ahead of their logic, so it may not use the\nname `handler`, and the combined function must fit CloudFront's 10 KB.\nIt runs on `cloudfront-js-2.0`, so it may be async and read\n{@link viewerRequestKeyValueStore} with `cf.kvs()`. A bring-your-own\n{@link distribution}'s default behavior isn't covered.",
18942
+ "stability": "stable",
18943
+ "summary": "CloudFront Function code run first on every viewer request, on every behavior cdk-nextjs adds, static assets included — HTTP Basic auth on a pre-launch site, geo-gating."
18944
+ },
18945
+ "immutable": true,
18946
+ "locationInModule": {
18947
+ "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18948
+ "line": 29
18949
+ },
18950
+ "name": "viewerRequestFunctionCode",
18951
+ "optional": true,
18952
+ "type": {
18953
+ "fqn": "aws-cdk-lib.aws_cloudfront.FunctionCode"
18954
+ }
18955
+ },
18956
+ {
18957
+ "abstract": true,
18958
+ "docs": {
18959
+ "default": "- none",
18960
+ "remarks": "Read it with `cf.kvs()`, no ID needed.",
18961
+ "stability": "stable",
18962
+ "summary": "A CloudFront KeyValueStore associated with every viewer-request function {@link viewerRequestFunctionCode} is copied into (up to three, one per kind of behavior), so values it reads — Basic auth credentials, an allowlist — live outside the CloudFormation template and change without a deploy."
18963
+ },
18964
+ "immutable": true,
18965
+ "locationInModule": {
18966
+ "filename": "src/generated-structs/OptionalNextjsDistributionProps.ts",
18967
+ "line": 15
18968
+ },
18969
+ "name": "viewerRequestKeyValueStore",
18970
+ "optional": true,
18971
+ "type": {
18972
+ "fqn": "aws-cdk-lib.aws_cloudfront.IKeyValueStore"
18973
+ }
18728
18974
  }
18729
18975
  ],
18730
18976
  "symbolId": "src/generated-structs/OptionalNextjsDistributionProps:OptionalNextjsDistributionProps"
@@ -19929,6 +20175,6 @@
19929
20175
  "symbolId": "src/nextjs-build/nextjs-build:PublicDirEntry"
19930
20176
  }
19931
20177
  },
19932
- "version": "0.7.12",
19933
- "fingerprint": "IKtjSb7QgT6alsb7At2pCRFLa7qU/0B4Qq6HYygyQ24="
20178
+ "version": "0.7.14",
20179
+ "fingerprint": "u/brpgNcCFVGp7OeUpdumZIHecf0FADTpvwAJMCUNZQ="
19934
20180
  }