aws-amplify / aws-amplify/amplify-hosting
Nextjs app fails to build SSR with error UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId'
- Dominant language
- Dockerfile
- Stars
- 481
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
### Before opening, please confirm:
- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
### App Id
d2cn4htefwf90t
### Region
ap-south-1
### Amplify Hosting feature
Backend builds, Build settings
### Describe the bug
NextJS application used to work previously. But initial configuration was using latest version of NextJS. So, I thought latest release of NextJS causing the failure, so I changed it to specific version(12.1.0 as my local machine) but SSR build is still failing with following error:
```
2022-04-27T09:13:39.482Z [INFO]: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
2022-04-27T09:13:39.765Z [INFO]: Starting SSR Build...
2022-04-27T09:16:17.312Z [ERROR]: MultipleValidationErrors: There were 6 validation errors:
* UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.DefaultCacheBehavior
* UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.CacheBehaviors.Items[0]
* UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.CacheBehaviors.Items[1]
* UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.CacheBehaviors.Items[2]
* UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.CacheBehaviors.Items[3]
* UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.CacheBehaviors.Items[4]
at ParamValidator.validate (/root/.//node_modules/aws-sdk/lib/param_validator.js:40:28)
at Request.VALIDATE_PARAMETERS (/root/.//node_modules/aws-sdk/lib/event_listeners.js:132:42)
at Request.callListeners (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at callNextListener (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:96:12)
at /root/.//node_modules/aws-sdk/lib/event_listeners.js:86:9
at finish (/root/.//node_modules/aws-sdk/lib/config.js:386:7)
at /root/.//node_modules/aws-sdk/lib/config.js:404:9
at SharedIniFileCredentials.get (/root/.//node_modules/aws-sdk/lib/credentials.js:127:7)
at getAsyncCredentials (/root/.//node_modules/aws-sdk/lib/config.js:398:24)
at Config.getCredentials (/root/.//node_modules/aws-sdk/lib/config.js:418:9)
at Request.VALIDATE_CREDENTIALS (/root/.//node_modules/aws-sdk/lib/event_listeners.js:81:26)
at Request.callListeners (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:102:18)
at Request.emit (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/root/.//node_modules/aws-sdk/lib/request.js:688:14)
at Request.transition (/root/.//node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/root/.//node_modules/aws-sdk/lib/state_machine.js:14:12)
at Request.runTo (/root/.//node_modules/aws-sdk/lib/request.js:408:15)
at /root/.//node_modules/aws-sdk/lib/request.js:797:12
at new Promise ()
at Request.promise (/root/.//node_modules/aws-sdk/lib/request.js:783:12)
at updateCloudFrontDistribution (/root/.//node_modules/@sls-next/aws-cloudfront/dist/index.js:218:53)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async CloudFront.default (/root/.//node_modules/@sls-next/aws-cloudfront/dist/component.js:60:30)
at async NextjsComponent.deploy (/root/.//node_modules/@sls-next/-component/dist/component.js:576:35)
at async fn (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/utils.js:280:41)
at async Promise.all (index 0)
at async executeGraph (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/utils.js:294:3)
at async Template.default (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/.js:67:38)
at async Object.runComponents (/root/.npm/_npx/780a6c1398234b48/node_modules/@/cli/src/index.js:222:17) {
code: 'MultipleValidationErrors',
errors: [
UnexpectedParameter: Unexpected key 'ResponseHeadersPolicyId' found in params.DistributionConfig.DefaultCacheBehavior
at ParamValidator.fail (/root/.//node_modules/aws-sdk/lib/param_validator.js:50:37)
at ParamValidator.validateStructure (/root/.//node_modules/aws-sdk/lib/param_validator.js:77:14)
at ParamValidator.validateMember (/root/.//node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validateStructure (/root/.//node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (/root/.//node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validateStructure (/root/.//node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (/root/.//node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validate (/root/.//node_modules/aws-sdk/lib/param_validator.js:34:10)
at Request.VALIDATE_PARAMETERS (/root/.//node_modules/aws-sdk/lib/event_listeners.js:132:42)
at Request.callListeners (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at callNextListener (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:96:12)
at /root/.//node_modules/aws-sdk/lib/event_listeners.js:86:9
at finish (/root/.//node_modules/aws-sdk/lib/config.js:386:7)
at /root/.//node_modules/aws-sdk/lib/config.js:404:9
at SharedIniFileCredentials.get (/root/.//node_modules/aws-sdk/lib/credentials.js:127:7)
at getAsyncCredentials (/root/.//node_modules/aws-sdk/lib/config.js:398:24)
at Config.getCredentials (/root/.//node_modules/aws-sdk/lib/config.js:418:9)
at Request.VALIDATE_CREDENTIALS (/root/.//node_modules/aws-sdk/lib/event_listeners.js:81:26)
at Request.callListeners (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:102:18)
at Request.emit (/root/.//node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/root/.//node_modules/aws-sdk/lib/request.js:688:14)
at Request.transition (/root/.//node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/root/.//node_modules/aws-sdk/lib/state_machine.js:14:12)
at Request.runTo (/root/.//node_modules/aws-sdk/lib/request.js:408:15)
at /root/.//node_modules/aws-sdk/lib/request.js:797:12
at new Promise ()
at Request.promise (/root/.//node_modules/aws-sdk/lib/request.js:783:12)
at updateCloudFrontDistribution (/root/.//node_modules/@sls-next/aws-cloudfront/dist/index.js:218:53)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async CloudFront.default (/root/.//node_modules/@sls-next/aws-cloudfront/dist/component.js:60:30)
at async NextjsComponent.deploy (/root/.//node_modules/@sls-next/-component/dist/component.js:576:35)
at async fn (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/utils.js:280:41)
at async Promise.all (index 0)
at async executeGraph (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/utils.js:294:3)
at async Template.default (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/.js:67:38)
at async Object.runComponents (/root/.npm/_npx/780a6c1398234b48/node_modules/@/cli/src/index.js:222:17)
```
### Expected behavior
Build is passing locally and on vercel but failing on amplify.
### Reproduction steps
1. Build NextJS application with following package.json
```
{
"name": "spotme",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@svgr/webpack": "^6.2.1",
"antd": "^4.19.2",
"csv-loader": "^3.0.3",
"formik": "^2.2.9",
"google-map-react": "^2.1.10",
"next": "12.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"sass": "^1.49.11",
"yup": "^0.32.11"
},
"devDependencies": {
"eslint": "8.11.0",
"eslint-config-next": "12.1.0"
}
}
```
### Build Settings
```yaml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```
### Additional information
Using custom image: node:15
Next.js version: 12.1.0
Contributor guide
Research direction
Start with the package.json and amplify.yml build settings, then trace the reported failure through @sls-next/aws-cloudfront at updateCloudFrontDistribution. Reproduce the SSR build using Next.js 12.1.0 and the node:15 image, and verify that the Amplify build completes without the ResponseHeadersPolicyId validation errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, nextjs, node.js, react
- Domain
- ci-cd, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100