Skip to content
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

feat(event_handlers): Add support for Lambda Function URLs #1408

Merged

Conversation

rubenfonseca
Copy link
Contributor

@rubenfonseca rubenfonseca commented Aug 3, 2022

Issue number: #1142, #1141

Summary

Changes

Please provide a summary of what's being changed

This PR adds support for Lambda Function URL events (data class) and event handlers.

Data Class

carbon (7)

For now, it seems that Lambda Function URL events follow the exact same payload as HTTP APIs Payload Format Version 2.0.

Event Handler

carbon (5)
carbon (6)

Certain keys in this payload format don't make sense for function urls (e.g: routeKey, stage). These keys will have default values that come on the payload, but they are not useful since they can't be changed.

User experience

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

Users could already use Lambda Function URLs before by using the API Gateway HTTP API data classes and handlers. However, we make the usage explicit and prepare for any future deviation from the API Gateway format.

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.


View rendered docs/core/event_handler/api_gateway.md
View rendered docs/index.md
View rendered docs/utilities/data_classes.md

@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 3, 2022
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation event_handlers logger tests utilities labels Aug 3, 2022
@github-actions github-actions bot added the feature New feature or functionality label Aug 3, 2022
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 3, 2022
@rubenfonseca rubenfonseca marked this pull request as ready for review August 3, 2022 12:24
@rubenfonseca rubenfonseca requested a review from a team as a code owner August 3, 2022 12:24
@rubenfonseca rubenfonseca requested review from heitorlessa and removed request for a team August 3, 2022 12:24
@gwlester
Copy link
Contributor

gwlester commented Aug 3, 2022

Looks good -- thanks much!!!!

Copy link

@jplock jplock left a comment

Choose a reason for hiding this comment

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

Please correct spelling errors

@rubenfonseca rubenfonseca requested a review from jplock August 3, 2022 20:29
@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2022

Codecov Report

Merging #1408 (eaebeee) into develop (144e9cc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop    #1408   +/-   ##
========================================
  Coverage    99.89%   99.89%           
========================================
  Files          119      121    +2     
  Lines         5456     5480   +24     
  Branches       624      627    +3     
========================================
+ Hits          5450     5474   +24     
  Misses           2        2           
  Partials         4        4           
Impacted Files Coverage Δ
aws_lambda_powertools/event_handler/__init__.py 100.00% <100.00%> (ø)
aws_lambda_powertools/event_handler/api_gateway.py 100.00% <100.00%> (ø)
...da_powertools/event_handler/lambda_function_url.py 100.00% <100.00%> (ø)
aws_lambda_powertools/logging/correlation_paths.py 100.00% <100.00%> (ø)
...mbda_powertools/utilities/data_classes/__init__.py 100.00% <100.00%> (ø)
.../utilities/data_classes/api_gateway_proxy_event.py 100.00% <100.00%> (ø)
...lambda_powertools/utilities/data_classes/common.py 100.00% <100.00%> (ø)
...tilities/data_classes/lambda_function_url_event.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@heitorlessa heitorlessa self-assigned this Aug 4, 2022
@rubenfonseca rubenfonseca changed the title feat(event_sources,event_handlers): Add support for Lambda Function URLs feat(event_handlers): Add support for Lambda Function URLs Aug 4, 2022
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.

looks great, thank you @rubenfonseca !!!! Minor suggestions that you can easily commit, then we're good to merge and release tomorrow!

@@ -546,6 +552,9 @@ def _to_proxy_event(self, event: Dict) -> BaseProxyEvent:
if self._proxy_type == ProxyEventType.APIGatewayProxyEventV2:
logger.debug("Converting event to API Gateway HTTP API contract")
return APIGatewayProxyEventV2(event)
if self._proxy_type == ProxyEventType.LambdaFunctionUrlEvent:
Copy link
Contributor

Choose a reason for hiding this comment

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

note to future self: we should improve the return type to a more accurate one with @overload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note to future self: wait for python 3.10 to actually have proper pattern matching

aws_lambda_powertools/event_handler/lambda_function_url.py Outdated Show resolved Hide resolved
aws_lambda_powertools/event_handler/lambda_function_url.py Outdated Show resolved Hide resolved
aws_lambda_powertools/logging/correlation_paths.py Outdated Show resolved Hide resolved
aws_lambda_powertools/event_handler/lambda_function_url.py Outdated Show resolved Hide resolved
docs/core/event_handler/api_gateway.md Outdated Show resolved Hide resolved
@@ -501,7 +526,7 @@ A micro function means that your final code artifact will be different to each f

**Downsides**

* **Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. `Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
* **Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
Copy link
Contributor

Choose a reason for hiding this comment

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

great catch!!

docs/index.md Outdated Show resolved Hide resolved
POWERTOOLS_SERVICE_NAME: example
FunctionUrlConfig:
Cors: # see CORS section
# Notice that values here are Lists of Strings, vs comma-separated values on API Gateway
Copy link
Contributor

Choose a reason for hiding this comment

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

Great note!

@heitorlessa
Copy link
Contributor

heitorlessa commented Aug 4, 2022 via email

@rubenfonseca rubenfonseca requested review from heitorlessa and removed request for jplock August 4, 2022 10:43
@heitorlessa
Copy link
Contributor

Merging! Should be out in our next release tomorrow

@heitorlessa heitorlessa merged commit 5dfc459 into aws-powertools:develop Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation event_handlers feature New feature or functionality logger size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests utilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants