Description
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Other
Environment information
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M3
Memory: 114.50 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.3.0 - ~/.asdf/installs/nodejs/v24.3.0/bin/node
Yarn: 1.22.22 - ~/.asdf/installs/nodejs/v24.3.0/bin/yarn
npm: 11.4.2 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 10.12.4 - ~/.asdf/installs/nodejs/v24.3.0/bin/pnpm
Browsers:
Chrome: 138.0.7204.50
Safari: 18.5
npmPackages:
@ampproject/toolbox-optimizer: undefined ()
@aws-amplify/adapter-nextjs: ^1.6.4 => 1.6.4
@aws-amplify/adapter-nextjs/api: undefined ()
@aws-amplify/adapter-nextjs/data: undefined ()
@aws-amplify/auth: ^6.13.1 => 6.13.1
@aws-amplify/auth/cognito: undefined ()
@aws-amplify/auth/cognito/server: undefined ()
@aws-amplify/auth/enable-oauth-listener: undefined ()
@aws-amplify/auth/server: undefined ()
@aws-sdk/client-cognito-identity-provider: ^3.839.0 => 3.839.0
@babel/core: undefined ()
@babel/runtime: 7.22.5
@edge-runtime/cookies: 6.0.0
@edge-runtime/ponyfill: 4.0.0
@edge-runtime/primitives: 6.0.0
@eslint/eslintrc: ^3 => 3.3.1
@hapi/accept: undefined ()
@mswjs/interceptors: undefined ()
@napi-rs/triples: undefined ()
@next/font: undefined ()
@opentelemetry/api: undefined ()
@tailwindcss/postcss: ^4 => 4.1.11
@types/jsonwebtoken: ^9.0.10 => 9.0.10
@types/node: ^20 => 20.19.2
@types/react: ^19 => 19.1.8
@types/react-dom: ^19 => 19.1.6
@typescript/vfs: undefined ()
@vercel/nft: undefined ()
@vercel/og: 0.6.8
acorn: undefined ()
amphtml-validator: undefined ()
anser: undefined ()
assert: undefined ()
async-retry: undefined ()
async-sema: undefined ()
aws-amplify: ^6.15.1 => 6.15.1
aws-amplify/adapter-core: undefined ()
aws-amplify/adapter-core/internals: undefined ()
aws-amplify/analytics: undefined ()
aws-amplify/analytics/kinesis: undefined ()
aws-amplify/analytics/kinesis-firehose: undefined ()
aws-amplify/analytics/personalize: undefined ()
aws-amplify/analytics/pinpoint: undefined ()
aws-amplify/api: undefined ()
aws-amplify/api/internals: undefined ()
aws-amplify/api/server: undefined ()
aws-amplify/auth: undefined ()
aws-amplify/auth/cognito: undefined ()
aws-amplify/auth/cognito/server: undefined ()
aws-amplify/auth/enable-oauth-listener: undefined ()
aws-amplify/auth/server: undefined ()
aws-amplify/data: undefined ()
aws-amplify/data/server: undefined ()
aws-amplify/datastore: undefined ()
aws-amplify/in-app-messaging: undefined ()
aws-amplify/in-app-messaging/pinpoint: undefined ()
aws-amplify/push-notifications: undefined ()
aws-amplify/push-notifications/pinpoint: undefined ()
aws-amplify/storage: undefined ()
aws-amplify/storage/s3: undefined ()
aws-amplify/storage/s3/server: undefined ()
aws-amplify/storage/server: undefined ()
aws-amplify/utils: undefined ()
babel-packages: undefined ()
browserify-zlib: undefined ()
browserslist: undefined ()
buffer: undefined ()
bytes: undefined ()
ci-info: undefined ()
cli-select: undefined ()
client-only: 0.0.1
commander: undefined ()
comment-json: undefined ()
compression: undefined ()
conf: undefined ()
constants-browserify: undefined ()
content-disposition: undefined ()
content-type: undefined ()
cookie: undefined ()
cross-spawn: undefined ()
crypto-browserify: undefined ()
css.escape: undefined ()
data-uri-to-buffer: undefined ()
debug: undefined ()
devalue: undefined ()
domain-browser: undefined ()
edge-runtime: undefined ()
eslint: ^9 => 9.30.0
eslint-config-next: 15.3.4 => 15.3.4
events: undefined ()
find-up: undefined ()
fresh: undefined ()
glob: undefined ()
gzip-size: undefined ()
http-proxy: undefined ()
http-proxy-agent: undefined ()
https-browserify: undefined ()
https-proxy-agent: undefined ()
icss-utils: undefined ()
ignore-loader: undefined ()
image-size: undefined ()
is-animated: undefined ()
is-docker: undefined ()
is-wsl: undefined ()
jest-worker: undefined ()
json5: undefined ()
jsonwebtoken: ^9.0.2 => undefined (9.0.2, )
loader-runner: undefined ()
loader-utils: undefined ()
lodash.curry: undefined ()
lru-cache: undefined ()
mini-css-extract-plugin: undefined ()
nanoid: undefined ()
native-url: undefined ()
neo-async: undefined ()
next: 15.3.4 => 15.3.4
node-html-parser: undefined ()
ora: undefined ()
os-browserify: undefined ()
p-limit: undefined ()
p-queue: undefined ()
patch-package: ^8.0.0 => 8.0.0
path-browserify: undefined ()
path-to-regexp: undefined ()
picomatch: undefined ()
postcss-flexbugs-fixes: undefined ()
postcss-modules-extract-imports: undefined ()
postcss-modules-local-by-default: undefined ()
postcss-modules-scope: undefined ()
postcss-modules-values: undefined ()
postcss-preset-env: undefined ()
postcss-safe-parser: undefined ()
postcss-scss: undefined ()
postcss-value-parser: undefined ()
prettier: ^3.6.2 => 3.6.2
process: undefined ()
punycode: undefined ()
querystring-es3: undefined ()
raw-body: undefined ()
react: ^19.0.0 => 19.1.0
react-builtin: undefined ()
react-dom: ^19.0.0 => 19.1.0
react-dom-builtin: undefined ()
react-dom-experimental-builtin: undefined ()
react-experimental-builtin: undefined ()
react-is: 19.2.0-canary-3fbfb9ba-20250409
react-refresh: 0.12.0
react-server-dom-turbopack-builtin: undefined ()
react-server-dom-turbopack-experimental-builtin: undefined ()
react-server-dom-webpack-builtin: undefined ()
react-server-dom-webpack-experimental-builtin: undefined ()
regenerator-runtime: 0.13.4
sass-loader: undefined ()
scheduler-builtin: undefined ()
scheduler-experimental-builtin: undefined ()
schema-utils: undefined ()
semver: undefined ()
send: undefined ()
server-only: 0.0.1
setimmediate: undefined ()
shell-quote: undefined ()
source-map: undefined ()
source-map08: undefined ()
sst: 3.17.8 => 3.17.8
stacktrace-parser: undefined ()
stream-browserify: undefined ()
stream-http: undefined ()
string-hash: undefined ()
string_decoder: undefined ()
strip-ansi: undefined ()
superstruct: undefined ()
tailwindcss: ^4 => 4.1.11
tar: undefined ()
terser: undefined ()
text-table: undefined ()
timers-browserify: undefined ()
tty-browserify: undefined ()
typescript: ^5 => 5.8.3
ua-parser-js: undefined ()
unistore: undefined ()
util: undefined ()
vm-browserify: undefined ()
watchpack: undefined ()
web-vitals: undefined ()
webpack: undefined ()
webpack-sources: undefined ()
ws: undefined ()
zod: undefined ()
zod-validation-error: undefined ()
npmGlobalPackages:
@google/gemini-cli: 0.1.5
corepack: 0.33.0
npm: 11.4.2
pnpm: 10.12.4
prettier: 3.6.2
sst: 3.17.8
yarn: 1.22.22
Describe the bug
instanceof Request
check in @aws-amplify/adapter-nextjs
breaks on AWS Lambda (OpenNext/SST)
Summary
When deploying a Next.js App Router project using the Amplify adapter (@aws-amplify/adapter-nextjs
) on AWS Lambda (via OpenNext/SST), authentication API routes (e.g., /api/auth/sign-in
) work on the first (cold) request, but subsequent (warm) requests return 500 errors:
Error: Invalid request and context/response combination. The request cannot be handled.
Root Cause
- The adapter uses this type guard:
function isNextRequest(request) { return request instanceof Request && 'nextUrl' in request; }
- In Lambda/serverless environments, due to bundling and process reuse, the
Request
constructor reference may differ between invocations. As a result,instanceof Request
fails even for valid Next.jsNextRequest
objects. - This causes the adapter to reject valid requests, leading to 500 errors on all but the first invocation.
Expected behavior
The /api/auth/...
endpoints should be stable and work in Lambda/OpenNext deployments.
Reproduction steps
- Configure server side auth as described here: https://docs.amplify.aws/react/build-a-backend/server-side-rendering/
- Deploy using OpenNext/SST to AWS Lambda.
- Make a request to an auth route (e.g.,
/api/auth/sign-in
) – it works on cold start. - Make a second request – it fails with a 500 and the error above.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response