hono icon indicating copy to clipboard operation
hono copied to clipboard

Multivalue query param support on AWS lambda behind apigateway

Open leaumar opened this issue 1 year ago • 3 comments

What version of Hono are you using?

4.6.3

What runtime/platform is your app running on?

AWS lambda node20

What steps can reproduce the bug?

Having an api gateway that calls a lambda where hono is listening, a request like GET http://.../helloworld?name=foo&name=bar results in our hono handlers only receiving the last multivalue, i.e. "bar" instead of ["foo","bar"] in a validator('query', ...) middleware. We're aware of the difference between ctx.req.query and ctx.req.queries but we don't use either, only ctx.req.valid('query').

We receive the full multivalue if we run the same hono app locally (so only apigateway and lambda are removed). We can also revert our "upgrade" from koa to hono on the current infrastructure (the same lambda config etc, just different js), and then koa gives us the full multivalue. So it seems to us this must be an issue in hono's integration with api gateway, not something wrong in our infrastructure or call.

What is the expected behavior?

validator('query', ...) should receive multivalue query params

What do you see instead?

only a single value is passed

Additional information

We had a glance at the hono code and believe https://github.com/honojs/hono/blob/main/src/adapter/aws-lambda/handler.ts#L285 is the relevant code, where multiValueQueryStringParameters would have to be used somehow.

But when we look at even the latest @types/aws-lambda, APIGatewayProxyEventV2 does not actually seem to have the field, contrary to what we understand from articles like this. Instead APIGatewayProxyEventMultiValueQueryStringParameters is used on APIGatewayProxyEventBase which APIGatewayProxyEventV2WithRequestContext doesn't extend. Our app does use an authorizer in front of our lambda and APIGatewayProxyWithLambdaAuthorizerEvent has multiValueQueryStringParameters, but we're not sure if that helps at all.

We don't really understand the reasoning in AWS' mess of payload types to be able to be more constructive, we never work with them, sorry. Maybe the most reasonable thing is for hono to just if ("multiValueQueryStringParameters" in event) { and parse it like here if true?

Thanks

leaumar avatar Oct 02 '24 14:10 leaumar

Thanks @leaumar

@watany-dev @exoego @yiss or others. Can anyone handle this?

yusukebe avatar Oct 04 '24 08:10 yusukebe

Thanks @leaumar I'll take look at it. What version of APIGateway are you using? V1 or v2?

yiss avatar Oct 04 '24 10:10 yiss

@yiss our api is listed as a REST type so googling actually tells me it's a V1.

leaumar avatar Oct 04 '24 16:10 leaumar

Is this (still) a problem?

mvierssen avatar Dec 15 '25 07:12 mvierssen