Skip to content

Conversation

@Sandy-Garrido
Copy link

@Sandy-Garrido Sandy-Garrido commented Jul 13, 2025

What does this PR do?

This PR fixes an issue in the bun-lambda package(noted in this issue #20760 ), specifically within the runtime.ts where 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 formatResponse function incorrectly constructed the Lambda response payload by including both the cookies and multiValueHeaders properties.

According to the AWS documentation:

Format 2.0 doesn't have multiValueHeaders or multiValueQueryStringParameters fields.

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.

  • Code changes

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.

@ivanbarlog
Copy link

@Sandy-Garrido if you are interested I've prepared CDK construct for Lambda Bun Runtime which contains also your fix.

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.

2 participants