Closed
Description
Expected Behaviour
As the documentation stated:
The client must send the Accept-Encoding header, otherwise a normal response will be sent.
When testing my API Gateway integration with lambda from the AWS Console, without specifying header, this send a null header.
Current Behaviour
Throw an error for a request with empty/null headers to a method with compress=True
:
'NoneType' object has no attribute 'items'", "errorType": "AttributeError"
That was due to an error from api_gateway.py at line 212:
if self.route.compress and "gzip" in (event.get_header_value("accept-encoding", "") or ""):
Code snippet
@tracer.capture_method
@app.post("/query/execute", compress=True)
def execute_query():
query: dict = app.current_event.json_body
.....
return {"message": "OK"}
@tracer.capture_lambda_handler
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST, log_event=True)
def lambda_handler(event, context):
return app.resolve(event, context)
Possible Solution
No response
Steps to Reproduce
- Create a AWS API Gateway type REST
- Add a Lambda with routing
- Enable compression for method, with compress=True
- Test from API Gateway the method from AWS Console and do not specify headers
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
Lambda Layers
Debugging logs
....
Wed Jul 20 09:18:47 UTC 2022 : HTTP Method: POST, Resource Path: /query/execute
Wed Jul 20 09:18:47 UTC 2022 : Method request path: {}
Wed Jul 20 09:18:47 UTC 2022 : Method request query string: {}
Wed Jul 20 09:18:47 UTC 2022 : Method request headers: {}
Wed Jul 20 09:18:47 UTC 2022 : Method request body before transformations: {
.....
.....
Wed Jul 20 09:18:50 UTC 2022 : Endpoint response body before transformations: {"errorMessage": "'NoneType' object has no attribute 'items'", "errorType": "AttributeError", "requestId": "REDACTED", "stackTrace": [" File \"/opt/python/aws_lambda_powertools/tracing/tracer.py\", line 315, in decorate\n response = lambda_handler(event, context, **kwargs)\n", " File \"/opt/python/aws_lambda_powertools/logging/logger.py\", line 354, in decorate\n return lambda_handler(event, context, *args, **kwargs)\n", " File \"/var/task/app.py\", line 59, in lambda_handler\n return app.resolve(event, context)\n", " File \"/opt/python/aws_lambda_powertools/event_handler/api_gateway.py\", line 503, in resolve\n return self._resolve().build(self.current_event, self._cors)\n", " File \"/opt/python/aws_lambda_powertools/event_handler/api_gateway.py\", line 217, in build\n self._route(event, cors)\n", " File \"/opt/python/aws_lambda_powertools/event_handler/api_gateway.py\", line 212, in _route\n if self.route.comp [TRUNCATED]
Wed Jul 20 09:18:50 UTC 2022 : Lambda execution failed with status 200 due to customer function error: 'NoneType' object has no attribute 'items'. Lambda request id: REDACTED
Wed Jul 20 09:18:50 UTC 2022 : Method completed with status: 502