Closed
Description
Use case
I have a lambda function with an ALB event source, I was attempting to use Response
(from aws_lambda_powertools.event_handler import content_types, Response)
instead of constructing the response by hand
return Response(
status_code=200,
body=data,
content_type=content_types.APPLICATION_JSON)
instead of
return {
"statusCode": 200,
"statusDescription": "200 OK",
"multiValueHeaders": {
"Content-Type": ["application/json"]
},
"body": data
}
the ALB responds with a 502 when using Response I suspect it is because multiValueHeaders is not included in the response.
To get around this, I am doing the following but it is not elegant
response = Response(
status_code=status_code,
body=data,
content_type=content_types.APPLICATION_JSON
).__dict__
response["multiValueHeaders"] = {
"Content-Type": ["application/json"]
}
return response
Solution/User Experience
I would like for the Response object to be able to detect multiValueHeaders
in the request and use that to determine if the response should do the same
Alternative solutions
An alternative could be to have MultiValueResponse object that works the same as Response but sends `multiValueHeaders`
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript