fix(aws-lambda): detect V2 events by request context, not rawPath alone#5016
Open
VihAMBR wants to merge 1 commit into
Open
fix(aws-lambda): detect V2 events by request context, not rawPath alone#5016VihAMBR wants to merge 1 commit into
VihAMBR wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
rawPathto the event.isProxyEventV2only checked whetherrawPathwas present, so these V1 events were treated as V2 (HTTP API). The handler then routed onrawPathand readrequestContext.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
httpobject on its request context; a V1 REST event does not. Checking for that alongsiderawPathkeeps real V2 events working and stops a V1 event with a base-pathrawPathfrom being misread as V2.Test
Added a
handletest that sends a V1 event carrying a base-pathrawPathand asserts it routes by itspath. It fails before the change (the event is handled as V2) and passes after.bun run format:fix && bun run lint:fixto format the code