aws-amplify / aws-amplify/amplify-hosting

Next.js 12/13 On-demand revalidation isn't working

Open
#3,116 5 comments 0 reactions 0 assignees View on GitHub
compute feature-request ssr
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.
- [X] I have removed any sensitive information from my code snippets and submission.

### App Id

d2dyf3i5dmf2ci

### AWS Region

sa-east-1

### Amplify Hosting feature

SSR

### Describe the bug

I was following this issue: #2343 and was happy today with announcement of public launch of 12/13 support. I was using Vercel while working on a project since i need "on demand revalidate" feature.

Then I created a fresh new Amplify app today, just connecting the same repository/branch used for Vercel app.

For my surprise, after all deploy process (nice to see it faster than before now), I see revalidate call not working.

It's a simplest, basic call just for testing, like url/api/revalidate wich fires revalidation to index page ("/").

Vercel response tried just now:
`{"revalidated":true}`

Amplify response tried just now:
`Error revalidating`

Vercel success response is shown in about 4~5 seconds. Amplify error is shown in about 10 seconds.

Is Next 12 support working already? Am I missing some Amplify exclusive setting to make it work?

Next.js config:
```
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
images: {
domains: [process.env.AMAZON_S3_DOMAIN],
},
};

module.exports = nextConfig;
```

Versions. I tried older (next 12.2.5) before, then updated and tried these with same results:
"aws-sdk": "^2.1257.0",
"next": "13.0.3",

Sorry if it's not a bug, I didn't selected "feature request" because it's a feature already requested and launched. didn't Selected question because the exact same repository just works in Vercel but not in Amplify, so I believe it's a bug. If it's not, please remove "bug" tag if I can't.

### Expected behavior

revalidation call working:
`{"revalidated":true}`

### Reproduction steps

a call to url/api/revalidate (no token used just for making test easier for now).

### Build Settings

```yaml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```

### Log output

```
# Put your logs below this line

Failed to update prerender cache for /index [Error: EROFS: read-only file system, open '/var/task/.next/server/pages/index.html'] {
errno: -30,
code: 'EROFS',
syscall: 'open',
path: '/var/task/.next/server/pages/index.html'
}
MissingRequiredParameter: Missing required key 'TableName' in params
at ParamValidator.fail (/var/task/node_modules/aws-sdk/lib/param_validator.js:50:37)
at ParamValidator.validateStructure (/var/task/node_modules/aws-sdk/lib/param_validator.js:62:14)
at ParamValidator.validateMember (/var/task/node_modules/aws-sdk/lib/param_validator.js:89:21)
at ParamValidator.validate (/var/task/node_modules/aws-sdk/lib/param_validator.js:34:10)
at Request.VALIDATE_PARAMETERS (/var/task/node_modules/aws-sdk/lib/event_listeners.js:132:42)
at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at callNextListener (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:96:12)
at /var/task/node_modules/aws-sdk/lib/event_listeners.js:86:9
at finish (/var/task/node_modules/aws-sdk/lib/config.js:396:7)
at /var/task/node_modules/aws-sdk/lib/config.js:438:9 {
code: 'MissingRequiredParameter',
time: 2022-11-17T22:55:20.194Z
}
TypeError: res.hasHeader is not a function
at Object.setRevalidateHeaders (/var/task/node_modules/next/dist/server/send-payload/revalidate-headers.js:8:37)
at Object.sendRenderResult (/var/task/node_modules/next/dist/server/send-payload/index.js:62:33)
REPORT RequestId: 32c96093-d335-49d8-81a7-a3aa49eadf62 Duration: 9106.08 ms Billed Duration: 9107 ms Memory Size: 1024 MB Max Memory Used: 149 MB Init Duration: 1101.52 ms
REPORT RequestId: 3172296f-60c9-44a6-9476-9dc85ccfa94a Duration: 11.36 ms Billed Duration: 12 ms Memory Size: 1024 MB Max Memory Used: 150 MB
```

### Additional information

at build time, index page is rendered as expected, but i can't fire revalidate on it.
the erros shown in log don't exist in local or vercel deploys...

Contributor guide

Open the contributing guide

Research direction

Start with the /api/revalidate reproduction on the reported Amplify app and compare its behavior with Vercel. Read the supplied Next.js configuration and build settings, then use the deployment logs as the entry point for the read-only filesystem, missing DynamoDB table name, and response-header errors. Done means the call returns {"revalidated":true} without those errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, next.js
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.