Use case
We use aws_lambda_powertools.event_handler.ALBResolver for internal HTTP requests. We ran into a case the other day where the lambda was returning successfully, but the response was over the 1MB limit for ALBs (docs), so the caller ended up getting a 502 status code.
I asked in the Discord channel and someone else said they've had a similar problem in the past:
It was tricky to track down because your lambda logs look great.
This happened today with the ALBResolver, but I'd imagine a similar problem could happen with APIGatewayHttpResolver and the 6MB response limit.
Solution/User Experience
The best idea I can come up with is:
- add a new flag to the ALBResolver initializer, like
enable_response_size_validation (and same for APIGatewayHttpResolver)
- When building the response, if the flag is enabled and the payload is too large for the corresponding resolver, raise a new exception, such as
ResponseSizeValidationError
- Users can add their own
ResponseSizeValidationError handler to log, etc.
I don't know if there's a more appropriate HTTP status code than 500 for this, since 413 Content Too Large is for the client.
To follow the letter of the law for backwards compatibility, the flag would have to be disabled by default. But I think (assuming no bugs) it would just be raising an error earlier and more visibly.
Alternative solutions
Logging when the response is too large? I'm not sure if there are other cases where the framework writes logs on its own.
I'm not sure if there's any built-in tracing that would you could add the response side and limit as attributes.
Acknowledgment
Use case
We use
aws_lambda_powertools.event_handler.ALBResolverfor internal HTTP requests. We ran into a case the other day where the lambda was returning successfully, but the response was over the 1MB limit for ALBs (docs), so the caller ended up getting a 502 status code.I asked in the Discord channel and someone else said they've had a similar problem in the past:
This happened today with the
ALBResolver, but I'd imagine a similar problem could happen withAPIGatewayHttpResolverand the 6MB response limit.Solution/User Experience
The best idea I can come up with is:
enable_response_size_validation(and same forAPIGatewayHttpResolver)ResponseSizeValidationErrorResponseSizeValidationErrorhandler to log, etc.I don't know if there's a more appropriate HTTP status code than 500 for this, since
413 Content Too Largeis for the client.To follow the letter of the law for backwards compatibility, the flag would have to be disabled by default. But I think (assuming no bugs) it would just be raising an error earlier and more visibly.
Alternative solutions
Acknowledgment