Skip to content

Bug: Event handler does not accept null header for compression #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tbuatois opened this issue Jul 20, 2022 · 4 comments
Closed

Bug: Event handler does not accept null header for compression #1327

tbuatois opened this issue Jul 20, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@tbuatois
Copy link
Contributor

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

  1. Create a AWS API Gateway type REST
  2. Add a Lambda with routing
  3. Enable compression for method, with compress=True
  4. 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
@tbuatois tbuatois added bug Something isn't working triage Pending triage from maintainers labels Jul 20, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Jul 20, 2022

Thanks for opening your first issue here! We'll come back to you as soon as we can.

@heitorlessa
Copy link
Contributor

hey @tbuatois thank you for flagging this and even for taking the time to solve it, much appreciated! Question for you: can this wait until our next release this Friday or is that impacting you now?

I suspect it's the former

@tbuatois
Copy link
Contributor Author

hey @tbuatois thank you for flagging this and even for taking the time to solve it, much appreciated! Question for you: can this wait until our next release this Friday or is that impacting you now?

I suspect it's the former

Hey @heitorlessa,

It can surely wait for the next release ! Thanks for asking.

@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Jul 25, 2022
@github-actions
Copy link
Contributor

This is now released under 1.26.6 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants