Skip to content

Bug: APIGateWayProxyEvent.request_context.authorizer results in KeyError #4102

Closed

Description

@dirkdebruin

Expected Behaviour

returns authorizer dictionary

Current Behaviour

KeyError

Code snippet

powertools-lambda-python/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py
line 94 in class APIGatewayEventRequestContext

 def authorizer(self) -> APIGatewayEventAuthorizer:
        return APIGatewayEventAuthorizer(self._data["requestContext"]["authorizer"])

Possible Solution

 def authorizer(self) -> APIGatewayEventAuthorizer:
        return APIGatewayEventAuthorizer(self.["requestContext"].get("authorizer"))

Steps to Reproduce

@event_source(data_class=APIGatewayProxyEvent)
def handler(event: APIGatewayProxyEvent, context):
    authorizer = event.request_context.authorizer

Powertools for AWS Lambda (Python) version

2.36.0

AWS Lambda function runtime

3.11

Packaging format used

PyPi

Debugging logs

No response

Activity

  1. added
    bugSomething isn't working
    triagePending triage from maintainers
    on Apr 10, 2024
  2. boring-cyborg commented on Apr 10, 2024

    @boring-cyborg

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

  3. rubenfonseca commented on Apr 10, 2024

    @rubenfonseca
    Contributor

    Looking now

  4. rubenfonseca commented on Apr 10, 2024

    @rubenfonseca
    Contributor

    Hi @dirkdebruin thank you for opening this issue!

    It seems that you are trying to use the Event Source feature directly without using any event handler resolver, which is ok.

    However, I need to understand more about which event source are you connecting this Lambda handler to.

    Can you please clear this up for me? Alternatively you could also paste the input payload (redact any unwanted info) that is being passed to the Lambda handler? Thank you!

  5. added
    triagePending triage from maintainers
    and removed
    triagePending triage from maintainers
    on Apr 10, 2024
  6. moved this from Triage to Pending customer in Powertools for AWS Lambda (Python)on Apr 10, 2024
  7. rubenfonseca commented on Apr 12, 2024

    @rubenfonseca
    Contributor

    Hi @dirkdebruin can you get me the information above so we can continue to debug the problem please?

  8. self-assigned this
    on Apr 12, 2024
  9. rubenfonseca commented on Apr 15, 2024

    @rubenfonseca
    Contributor

    Hi again @dirkdebruin happy to continue looking into this if you get me some more information :)

  10. 6 remaining items

  11. heitorlessa commented on May 7, 2024

    @heitorlessa
    Contributor

    Leandro reproduced - it doesn't happen at runtime, the key authorizer is always present when there's an authorizer.

    That said, we still need to make it safe to access a authorizer property and return an empty dictionary to prevent a KeyError when testing locally.

    I'll get back to this as soon as I handle a runtime bug #4277

  12. added
    event_sourcesEvent Source Data Class utility
    and removed
    bugSomething isn't working
    on May 8, 2024
  13. heitorlessa commented on May 8, 2024

    @heitorlessa
    Contributor

    Updated to not-a-bug to reflect our tests... however we'll include sane default values for container types (dict/list) to avoid this situation in non-prod.

    That means accessing claims will return an empty dict if not available, or an empty list when accessing scopes and that isn't available, and so on.

  14. moved this from Pending customer to Pending review in Powertools for AWS Lambda (Python)on May 8, 2024
  15. moved this from Pending review to Coming soon in Powertools for AWS Lambda (Python)on May 9, 2024
  16. github-actions commented on May 9, 2024

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    This issue is now closed. Please be mindful that future comments are hard for our team to see.

    If you need more assistance, please either tag a team member or open a new issue that references this one.

    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  17. github-actions commented on May 17, 2024

    @github-actions
    Contributor

    This is now released under 2.38.0 version!

  18. moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python)on Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions