Skip to content

aws-lambda streaming handler doesn't work with API Gateway REST API (v1) #4128

@sumi-mtk

Description

@sumi-mtk

Environment

  • nitropack: 2.11.12 (via nuxt 3.16.1)
  • Node.js: 24.x
  • AWS Lambda runtime: nodejs24.x
  • API Gateway: REST API (v1), not HTTP API (v2)
  • Deployment: SAM with aws_proxy + responseTransferMode: STREAM

Reproduction

No StackBlitz reproduction since this requires a real AWS deployment. The issue is visible by reading the source directly:

https://github.com/nitrojs/nitro/blob/main/src/presets/aws-lambda/runtime/aws-lambda-streaming.ts

The streaming handler reads event.rawPath and event.requestContext?.http?.method, which are HTTP API v2 properties. REST API v1 uses event.path and event.httpMethod instead.

The non-streaming handler already handles both:

// aws-lambda.ts — works
const url = withQuery(event.path || event.rawPath, query);
const method = event.httpMethod || event.requestContext?.http?.method || "get";

Describe the bug

Setting awsLambda.streaming: true and deploying behind API Gateway REST API causes a 302 redirect loop.

REST API v1 sends event.path and event.httpMethod. The streaming handler ignores these and only reads event.rawPath (v2). Since rawPath is undefined in v1 events, the URL resolves to undefined, Nitro can't match any route, and it returns a 302 redirect to the same path — looping forever.

The fix is straightforward — the streaming handler should match the non-streaming one:

- const url = withQuery(event.rawPath, query);
- const method = event.requestContext?.http?.method || "get";
- const query = { ...event.queryStringParameters };
+ const url = withQuery(event.path || event.rawPath, query);
+ const method = event.httpMethod || event.requestContext?.http?.method || "get";
+ const query = { ...event.queryStringParameters, ...event.multiValueQueryStringParameters };

The type annotation (APIGatewayProxyEventV2) should also be widened to accept v1 events.

Additional context

We're working around this by patching the compiled output with sed after nuxt build. Happy to open a PR if that would be preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions