awslabs / aws-lambda-web-adapter

Run web applications on AWS Lambda
Apache License 2.0
1.92k stars 115 forks source link

Enabling 'Multi value headers' gives 502 by ALB #462

Closed ashwinspg closed 5 months ago

ashwinspg commented 5 months ago

Description

In our use case, we configured ALB by pointing lambda as target. This lambda is deployed with AWS Lambda Web Adapter to run http service.

In one of our API endpoint, we had a requirement on query parameters with multiple values for the same key. It is working as expected when the web application is deployed locally for testing.

What is the problem?

When we deployed the same to AWS environment using AWS Lambda Web Adapter. We observe that the application logic can get only last value of the query parameter.

To resolve this, we come to know about this: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers

By default 'Multi value headers' is disabled. Based on this, we enabled 'Multi value headers' in the target group.

After this configuration, we get '502 Bad Gateway' as response for every API requests even without multiple values for the same key.

In the logs, we see following error:

thread 'main' panicked at 'failed to build request: http::Error(InvalidUri(InvalidFormat))', /root/.cargo/git/checkouts/aws-lambda-rust-runtime-bf4c93ddbea2f260/9ee217c/lambda-http/src/request.rs:230:10
bnusunny commented 5 months ago

@ashwinspg what's the LWA version you have this issue? Could you share one sample request as well?

ashwinspg commented 5 months ago

This issue is associated with LWA version: 0.3.2.

Enabling 'Multi value headers' in target group on AWS console and using LWA itself is creating a problem (throwing 502) irrespective of with/without multi value query string parameter.

@bnusunny

bnusunny commented 5 months ago

0.3.2 is an old version. I tested with the latest version 0.8.3. It does not throw 502 and should work with "Multi value headers". Let me know if it works for you.

@ashwinspg

ashwinspg commented 5 months ago

Updating the version to 0.8.3 resolves the problem.

Thank you for the support 👍

@bnusunny