Skip to content

feat(event_sources): add get_context() to standardize API Gateway Lambda Authorizer context in v1 and v2 #3454

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

Merged
merged 9 commits into from
Dec 6, 2023
Merged

Conversation

leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented Dec 5, 2023

Issue number: #3453
Other issue: #3444

Summary

Changes

We were using the wrong payload for v2 and assuming that this Payload contained a key called lambda. We updated the payload according to AWS Documentation.

User experience

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools import Logger

app = APIGatewayRestResolver()
logger = Logger(level="INFO")


@app.get("/")
def initialize():
    context: dict = app.current_event.request_context.authorizer.get_context()
    logger.info(context.get("tenantId"))

def lambda_handler(event, context):
    return app.resolve(event, context)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team December 5, 2023 11:01
@boring-cyborg boring-cyborg bot added the tests label Dec 5, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 5, 2023
@leandrodamascena leandrodamascena linked an issue Dec 5, 2023 that may be closed by this pull request
@heitorlessa heitorlessa added the event_sources Event Source Data Class utility label Dec 5, 2023
@heitorlessa heitorlessa changed the title fix(event_source): Remove wrong lambda property fix(event_sources): remove get_lambda property from API Gateway Request Context Authorizer v2 Dec 5, 2023
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! minor changes to improve the end customer experience by having good defaults.

@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (05dd82b) 95.42% compared to head (8d65889) 95.40%.

❗ Current head 8d65889 differs from pull request most recent head 3c07329. Consider uploading reports for the commit 3c07329 to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3454      +/-   ##
===========================================
- Coverage    95.42%   95.40%   -0.02%     
===========================================
  Files          209      209              
  Lines         9664     9668       +4     
  Branches      1773      812     -961     
===========================================
+ Hits          9222     9224       +2     
- Misses         329      330       +1     
- Partials       113      114       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@heitorlessa heitorlessa changed the title fix(event_sources): remove get_lambda property from API Gateway Request Context Authorizer v2 feat(event_sources): add get_context() to standardize API Gateway Context Authorizer in v1 and v2 Dec 6, 2023
@heitorlessa heitorlessa changed the title feat(event_sources): add get_context() to standardize API Gateway Context Authorizer in v1 and v2 feat(event_sources): add get_context() to standardize API Gateway Lambda Authorizer context in v1 and v2 Dec 6, 2023
Copy link

sonarqubecloud bot commented Dec 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event_sources Event Source Data Class utility size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
3 participants