fix(bun-lambda): Resolve 502 error when setting cookies with HTTP API Gateway (#20760) #21018
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.
What does this PR do?
This PR fixes an issue in the bun-lambda package(noted in this issue #20760 ), specifically within the
runtime.tswhere responses containing cookies would cause a 502 Bad Gateway error when used with an AWS HTTP API Gateway (v2.0 payload format).The root cause was that the
formatResponsefunction incorrectly constructed the Lambda response payload by including both the cookies and multiValueHeaders properties.According to the AWS documentation:
This change updates formatResponse to conditionally check the event type and correctly format the response:
For HTTP APIs (v2.0 events), it uses the cookies property.
For REST APIs (v1.0 events), it falls back to using multiValueHeaders.
This ensures the generated payload is always valid for the corresponding API Gateway type, resolving the 502 errors without breaking compatibility for users of REST APIs.
How did you verify your code works?
I have manually verified the fix by deploying a simple Hono application using the modified bun-lambda runtime to AWS Lambda.
Environment: AWS Lambda with an HTTP API Gateway (v2.0 payload).
Test Case: A simple endpoint that sets a cookie using hono/cookie.
Result: With these changes, the endpoint correctly returns a 200 OK response and successfully sets the cookie in the browser. Before this fix, the same deployment would consistently fail with a 502 Bad Gateway error.