Skip to content

fix(event_handler): make HttpResolverLocal usable as a Lambda handler - #8634

Open
jasperdingg wants to merge 1 commit into
aws-powertools:developfrom
jasperdingg:fix/http-resolver-lambda-handler
Open

jasperdingg wants to merge 1 commit into
aws-powertools:developfrom
jasperdingg:fix/http-resolver-lambda-handler

Conversation

@jasperdingg

@jasperdingg jasperdingg commented Oct 19, 2026 •

Copy link
Copy Markdown

Issue number: closes #8582 (item 3; items 1 and 2 are in #8633)

Summary

Changes

Please provide a summary of what's being changed

  • 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.
  • HTTP API v2 and Function URL events are mapped to APIGatewayProxyEventV2 instead of failing with KeyError: 'httpMethod'.
  • Request bodies that aren't valid UTF-8 are base64-encoded instead of raising UnicodeDecodeError.

User experience

Please share what the user experience looks like before and after this change

Before: handler = app raised TypeError: missing 'send', v2 events raised KeyError, and binary bodies through ASGI raised UnicodeDecodeError.

After: handler = app works 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.

- __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)
@jasperdingg
jasperdingg requested a review from a team as a code owner October 19, 2026 05:50
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 19, 2026
@boring-cyborg

boring-cyborg Bot commented Oct 19, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event_handlers size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

2 participants