Taken at face value, it looks like this parameter is missing from a configuration value somewhere in the Next.js app, deployed Lambda, etc. I'm not sure where this comes from yet, or who / what is responsible for supplying it, but it seems like it should be required. Also, it seems at least possible this is just a red herring for something bigger / different, but I'm creating this issue as a starting point.
Here are the steps I took to reproduce this error:
-
Create new AWS Account
To do this I just created a brand new account in my organization.
-
Start a brand new NextJS project
npx create-next-app@latest
Note: here are the resulting dep versions:
{
"name": "nextjs-cdk-test",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@types/node": "20.3.1",
"@types/react": "18.2.13",
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"eslint": "8.43.0",
"eslint-config-next": "13.4.6",
"next": "13.4.6",
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"typescript": "5.1.3"
}
}
- Start new CDK project
npx cdk init sample-app —language typescript
Note: here are the resulting dep versions:
{
"name": "cdk",
"version": "0.1.0",
"bin": {
"cdk": "bin/cdk.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"@types/node": "20.1.7",
"aws-cdk": "2.84.0",
"cdk-nextjs-standalone": "^3.2.0",
"esbuild": "^0.17.16",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "~5.0.4"
},
"dependencies": {
"aws-cdk-lib": "2.84.0",
"constructs": "^10.0.0"
}
}
- Move the Next.js app into a sub-directory into the CDK directory called “web”
- In root directory, bootstrap CDK
cdk bootstrap aws://XX4312/us-east-2 —profile nextjs-cdk-test-deployer
SUCCESS!!
~/S/c/t/**cdk** … cdk bootstrap aws://XX4312/us-east-2 —profile nextjs-cdk-test-deployer 1181ms Wed Jun 21 12:33:46 2023
⏳ Bootstrapping environment aws://XX4312/us-east-2…
Trusted accounts for deployment: (none)
Trusted accounts for lookup: (none)
Using default execution policy of ‘arn:aws:iam::aws:policy/AdministratorAccess’. Pass ‘—cloudformation-execution-policies’ to customize.
**CDKToolkit**: creating CloudFormation changeset…
✅ Environment aws://XX4312/us-east-2 bootstrapped.
- Follow directions on quickstart
https://github.com/jetbridge/cdk-nextjs
In short, I added the dependencies listed
npm install -D [email protected] cdk-nextjs-standalone
Then modified the sample-app CDK stack as such:
import { Stack, StackProps } from “aws-cdk-lib”;
import { Nextjs } from “cdk-nextjs-standalone”;
import { Construct } from “constructs”;
export class CdkStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new Nextjs(this, “Web”, {
nextjsPath: “./web”, // relative path to nextjs project root
});
}
}
- Running synth results in failure because no region specified
cdk synth CdkStack —profile nextjs-cdk-test-deployer
...
...
Error: stacks which use EdgeFunctions must have an explicitly set region
- Update default cdk stack config with region fixes EdgeFunction issue
I just modified the default (otherwise unmodified) bin/cdk.ts
file produced from the cdk init sample-app ..
to include a region (and I also added my account number:
#!/usr/bin/env node
import * as cdk from “aws-cdk-lib”;
import { CdkStack } from “../lib/cdk-stack”;
const app = new cdk.App();
new CdkStack(app, “CdkStack”, {
env: { account: “XX4312”, region: “us-east-2” },
});
- Cdk synth worked now
cdk synth CdkStack —profile nextjs-cdk-test-deployer
┌ Building Next.js app ▼ ...
├ Running "npx --yes open-next build" in ./web
Next.js v13.4.6
OpenNext v2.0.0
┌─────────────────────────────────┐
│ OpenNext — Building Next.js app │
└─────────────────────────────────┘
> [email protected] build
> next build
- info Creating an optimized production build
- info Compiled successfully
- info Linting and checking validity of types
- info Collecting page data
- info Generating static pages (4/4)
- info Finalizing page optimization
Route (app) Size First Load JS
┌ ○ / 0 B 0 B
└ ○ /favicon.ico 0 B 0 B
+ First Load JS shared by all 77.6 kB
├ chunks/769-8ab68f842512379f.js 25.2 kB
├ chunks/bce60fc1-49ee79ad31766ac6.js 50.5 kB
├ chunks/main-app-c2f0e612a52199d9.js 216 B
└ chunks/webpack-737972036df45a17.js 1.64 kB
Route (pages) Size First Load JS
─ ○ /404 182 B 74.7 kB
+ First Load JS shared by all 74.5 kB
├ chunks/framework-8883d1e9be70c3da.js 45 kB
├ chunks/main-542a92a81d12d254.js 27.7 kB
├ chunks/pages/_app-998b8fceeadee23e.js 195 B
└ chunks/webpack-737972036df45a17.js 1.64 kB
○ (Static) automatically rendered as static HTML (uses no initial props)
┌──────────────────────────────┐
│ OpenNext — Generating bundle │
└──────────────────────────────┘
Bundling static assets...
Bundling cache assets...
Bundling server function...
Bundling revalidation function...
Bundling image optimization function...
Bundling warmer function...
+ cd /Users/kevin/Sites/cdk-nextjs-sandbox/test-2/cdk/web/.open-next/server-function
+ zip -ryq1 /var/folders/1b/0m12cbyn1td6lf9_25xr4v5w0000gn/T/nextjs-cdk-build-gUn9Sj/standalone/serverFn.zip .
+ cd /var/folders/1b/0m12cbyn1td6lf9_25xr4v5w0000gn/T/nextjs-cdk-build-gUn9Sj/static
+ zip -ryq1 /var/folders/1b/0m12cbyn1td6lf9_25xr4v5w0000gn/T/nextjs-cdk-build-gUn9Sj/static/assets/assets.zip .
└ Finished preparing NextJS app for deployment
Resources:
WebBucketE51352C0:
Type: AWS::S3::Bucket
Properties:
Tags:
- Key: aws-cdk:auto-delete-objects
Value: "true"
...
...
- Trying to deploy resulted in bootstrap error (even though I already bootstrapped?)
I’m not sure why, but when I ran cdk deploy
I got an error, even though I already ran cdk bootstrap — profile …
- running cdk bootstrap
again
cdk bootstrap —profile nextjs-cdk-test-deployer
did show that one region was bootstrapped, but not another. So perhaps there is some sort of multi-region (something?) that is required by the Next.js cdk setup? Note below “no changes” for one region but not the other.
...
...
CDKToolkit: creating CloudFormation changeset...
✨ hotswap deployment skipped - no changes were detected (use --force to override)
✅ Environment aws://XX4312/us-east-2 bootstrapped (no changes).
✅ Environment aws://XX4312/us-east-1 bootstrapped.
...
...
- Cdk deploy
cdk deploy CdkStack —profile nextjs-cdk-test-deployer
This “worked”, deploy kicked off (prompted to confirm security changes and such, but kicked off as expected).
Do you wish to deploy these changes (y/n)? y
**CdkStack**: deploying… [1/2]
**CdkStack**: creating CloudFormation changeset…
✅ CdkStack
✨ Deployment time: 570.86s
Stack ARN:
arn:aws:cloudformation:us-east-2:XX4312:stack/CdkStack/2ea9c7c0-1054-11ee-b947-06023923a9b7
✨ Total time: 581.29s
- Login to management console to view domain for CloudFront
I’m not aware of any other way to get the cloud front distribution domain name, so I just logged into the AWS console to get the domain, in my case
- Visiting domain in a browser results in Next.js’s 500 error page
Note that the favicon.ico
request also resulted in a 500
- Visiting the Lambda console, I see multiple Lambdas were created
- CloudWatch logs for the “WebServerHandler” show repeated errors
E.g.
2023-06-21T17:04:38.390Z 75882801-8e7c-4100-9c33-6101a6aec3f9 ERROR {
clientName: 'S3Client',
commandName: 'ListObjectsV2Command',
input: { Bucket: undefined, Prefix: 'ggXh0qs_tsiubcOgG_DEu/index' },
error: Error: No value provided for input HTTP label: Bucket.
at _V (/var/task/cache.cjs:15:9782)
at ase (/var/task/cache.cjs:31:99926)
at async /var/task/cache.cjs:2:382,
metadata: undefined
}
The other Lambda logs didn’t seem to have anything that looked like errors