Repository navigation
fix(event_handler): make HttpResolverLocal usable as a Lambda handler - #8634
leandrodamascena merged 3 commits into
Conversation
- __call__ dispatches (event, context) to resolve() and (scope, receive, send) to the ASGI handler. The async handler is also exposed as the instance's __call__ attribute so uvicorn and hypercorn still detect an ASGI3 application. - Map v2 payload events (HTTP API, Function URL) to APIGatewayProxyEventV2. - Base64-encode request bodies that are not valid UTF-8. Refs aws-powertools#8582 (item 3)
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
…rLocal handles a v1 event
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @jasperdingg, the three fixes are right and I confirmed them with real uvicorn and hypercorn runs and behind a real HTTP API. The one thing the fixtures could not show: behind a real REST API, handler = app returned 502 on every request, because the resolver always answered in the HTTP API shape and REST rejects any response that carries a cookies key. I pushed a small commit that maps v1 events to APIGatewayProxyEvent so the response comes out with multiValueHeaders, plus two tests pinning both shapes. After that REST, HTTP API and the ASGI servers all behave.
Approving. This goes out in 3.39.0, so it will sit here for a while before I merge it. No rebase needed in the meantime, and you'll be credited in the release notes.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8634 +/- ##
========================================
Coverage 96.99% 96.99%
========================================
Files 321 321
Lines 16318 16331 +13
Branches 1470 1473 +3
========================================
+ Hits 15827 15840 +13
Misses 350 350
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dd46858
into
aws-powertools:develop
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |



Issue number: closes #8582
Summary
Changes
HttpResolverLocal.__call__now works as both a Lambda handler(event, context)and an ASGI app(scope, receive, send). The async ASGI handler is also set as the instance's__call__attribute, so uvicorn and hypercorn still detect it as an ASGI3 app.APIGatewayProxyEventV2instead of failing withKeyError: 'httpMethod'.UnicodeDecodeError.User experience
Before:
handler = appraisedTypeError: missing 'send', v2 events raisedKeyError, and binary bodies through ASGI raisedUnicodeDecodeError.After:
handler = appworks in Lambda for REST, HTTP API and Function URL events, the same app still runs under uvicorn and hypercorn, and binary bodies arrive base64-encoded.Tested w/ new tests in
test_http_resolver.py, plus a manual run under uvicorn on Python 3.11 and 3.14.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.