Skip to content

Conversation

@chriselion
Copy link

Issue number: closes #7621

Summary

From https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html, for ALB requests

If the query parameters are URL-encoded, the load balancer does not decode them. You must decode them in your Lambda function

This adds a flag to ALBResolver to decode the query parameters before they are validated.

Changes

  • Add a decode_query_parameters flag to ALBResolver initializer.
  • Add a decode_query_parameters to ALBEvent. This defaults to false.
    • I thought about adding a **kwargs argument to the BaseProxyEvent initializers, but didn't love that.
  • Add ALBResolver._to_proxy_event (overrides the parent method). This calls the parent method, and sets a decode_query_parameters flag on the resulting ALBEvent.
  • Added functional test to ensure that an encoded datetime string could be passed to a route that accepts a datetime parameter, and a unit test for the ALBEvent decoding.

User experience

No change to the user experience - default behavior is the same, and users have to opt-in to get the new behavior.


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.

@chriselion chriselion requested a review from a team as a code owner January 11, 2026 04:18
@chriselion chriselion requested a review from sdangol January 11, 2026 04:18
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 11, 2026
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 11, 2026

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

"""Amazon Application Load Balancer (ALB) resolver
Parameters
Copy link
Author

Choose a reason for hiding this comment

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

These are copied from ApiGatewayResolver (except for decode_query_parameters, obviously)

@override
def _to_proxy_event(self, event: dict) -> BaseProxyEvent:
proxy_event = super()._to_proxy_event(event)
if isinstance(proxy_event, ALBEvent):
Copy link
Author

Choose a reason for hiding this comment

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

This should always be the case, but I think mypy would complain if I didn't.

Alternatively, I could just create the ALBEvent here, but if the base method ever changes, that could break.

@override
def __init__(self, data: dict[str, Any], json_deserializer: Callable | None = None):
super().__init__(data, json_deserializer)
self.decode_query_parameters = False
Copy link
Author

Choose a reason for hiding this comment

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

This gets overridden in ALBResolver._to_proxy_event.

# Decode the parameter keys and values
decoded_params = {}
for k, vals in params.items():
decoded_params[unquote(k)] = [unquote(v) for v in vals]
Copy link
Author

Choose a reason for hiding this comment

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

Decoded the keys for consistency. That's what it looks like other frameworks do, although I'm not sure it would be useful here.

@@ -1,4 +1,5 @@
import base64
import datetime
Copy link
Author

Choose a reason for hiding this comment

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

Is this the best file for this test? I originally started here, but not sure if something like tests/functional/event_handler/_pydantic/test_api_gateway.py is better.

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.72%. Comparing base (7b93028) to head (a8981cc).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
aws_lambda_powertools/event_handler/api_gateway.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7940      +/-   ##
===========================================
- Coverage    96.72%   96.72%   -0.01%     
===========================================
  Files          278      278              
  Lines        13607    13626      +19     
  Branches      1080     1083       +3     
===========================================
+ Hits         13162    13180      +18     
  Misses         327      327              
- Partials       118      119       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Development

Successfully merging this pull request may close these issues.

Feature request: Add a flag to ALBResolver to URL-decode query parameters

1 participant