Skip to content

fix(aws-lambda): detect V2 events by request context, not rawPath alone#5016

Open
VihAMBR wants to merge 1 commit into
honojs:mainfrom
VihAMBR:fix/aws-lambda-v1-rawpath-misdetection
Open

fix(aws-lambda): detect V2 events by request context, not rawPath alone#5016
VihAMBR wants to merge 1 commit into
honojs:mainfrom
VihAMBR:fix/aws-lambda-v1-rawpath-misdetection

Conversation

@VihAMBR

@VihAMBR VihAMBR commented Jun 9, 2026

Copy link
Copy Markdown

Fixes #5015

What this fixes

When a Lambda is served through an API Gateway REST API (V1) with a custom domain base path mapping, API Gateway adds a rawPath to the event. isProxyEventV2 only checked whether rawPath was present, so these V1 events were treated as V2 (HTTP API). The handler then routed on rawPath and read requestContext.http, which a V1 event does not have, so the request never reached its route.

Every genuine V2 event (HTTP API and Lambda function URLs) carries an http object on its request context; a V1 REST event does not. Checking for that alongside rawPath keeps real V2 events working and stops a V1 event with a base-path rawPath from being misread as V2.

Test

Added a handle test that sends a V1 event carrying a base-path rawPath and asserts it routes by its path. It fails before the change (the event is handled as V2) and passes after.


  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

A V1 (REST API) event behind a custom domain base path mapping also
carries a rawPath, so checking for rawPath alone made isProxyEventV2
classify it as a V2 event. The request was then routed on the wrong
path and the V2 processor read fields the V1 event does not have.

Require the V2-only requestContext.http instead, which every HTTP API
and function URL event includes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws-lambda handler misinterprets V1 events as V2 events when using base path mappings

1 participant