-
Notifications
You must be signed in to change notification settings - Fork 421
Add APIGateway*EventModelV2 to parser #434
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
Comments
Hey @xpayn - Absolutely, I'd love to help with any guidance if you can make a PR. |
@heitorlessa note, we would have to ensure the any of the data classes are json serializable (ie: Idempotent handler expects a dict or something that can be serialized to json) |
Sure, it'd need an additional check if it's a Pyndantic Model, then you can call |
@xpayn @heitorlessa if you havent started it yet, i can do it this week.i created the v1 one and this was on my todo list |
see #441 |
I was planning to make the PR today, I just wanted to review my code before, but i'll read your's instead |
@xpayn @risenberg-cyberark Below is what i mean as an equivalent implementation for event source data classes (all of the in fact), and you would also @lambda_handler_decorator
def event_source(
handler: Callable[[Any, LambdaContext], Any],
event: Dict[str, Any], context: LambdaContext,
data_class: Type[DictWrapper],
):
# Where `model` is the passed in event source data class like APIGatewayProxyEventV2.
return handler(data_class(event), context) Usage wise, it would look like this from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEventV2
@event_source(data_class=APIGatewayProxyEventV2)
def lambda_handler(event: APIGatewayProxyEventV2, context: LambdaContext) -> Dict[str, Any]:
assert event.get_header_value("x-foo") == "Foo" To test: lambda_handler({"headers": {"X-Foo": "Foo"}}, None) |
@heitorlessa @xpayn @risenberg-cyberark created then equivalent for the event source data classes see PR #442 .
|
Co-authored-by: Heitor Lessa <[email protected]> Co-authored-by: heitorlessa <[email protected]>
note that the @event_parser(model=APIGatewayProxyEventV2Model)
@idempotent(persistence_store=persistence_layer)
def lambda_handler(event, _):
... Will raise a TypeError
See how this was resolved for the event_source implementation : @event_parser(model=APIGatewayProxyEventV2Model)
@idempotent(persistence_store=persistence_layer)
def lambda_handler(event, _):
... |
hey @xpayn - this is now available as part of 1.17.0 🎉 - I've added an example using both Model and Envelope for HTTP API: https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v1.17.0 Big thanks to @risenberg-cyberark on the implementation |
I think that being able to use the parser module with APIGatewayV2 would be a nice little ergonomic improvement.
today my code looks like:
It's not a big diffence but I think it looks better like this
If you accept PR and I have some spare time, I'll try to make something.
Thx
The text was updated successfully, but these errors were encountered: