-
Notifications
You must be signed in to change notification settings - Fork 407
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
Bug: event_source decorator with APIGatewayProxyEventV2 causes TypeError in debug mode #1152
Comments
Hey @sthuber90 tha is for reporting it - we'll look into it as soon as we can. Any particular reason you're using event_source with Event Handler? We already do that for you upon a Lambda invocation, and make it available under app.current_event property. Thanks!! |
Thank you. No, no particular reason combining |
Ah great, I was mostly curious if you knew. For the decorator, I need to
double check in the custom serializer part but IIRC it should work, as we
reuse it elsewhere.
…On Mon, 25 Apr 2022 at 19:30, Stephan ***@***.***> wrote:
Thank you. No, no particular reason combining @event_source and
APIGatewayHttpResolver. It's perfectly fine for me to remove the event
source decorator. Are the resolver and event source incompatible? If so, I
didn't see it in the docs
—
Reply to this email directly, view it on GitHub
<#1152 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBDJ3ZAIEHHNN2MFAO3VG3JC5ANCNFSM5UJG3LXA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Changes: - Allow for event being of type 'BaseProxyEvent' - Add test case closes aws-powertools#1152
@heitorlessa @sthuber90 - i am sorry for missing this edge case, but it is pretty valid if your handler wants to use the data class. So i put up a PR which is pretty small. Otherwise a current workaround would be: @logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP)
@event_source(data_class=APIGatewayProxyEventV2)
def lambda_handler(event: APIGatewayProxyEventV2, context: LambdaContext):
return app.resolve(event.raw_event, context) One thing i notices is that PyCharm does infer that event should be a dict. |
thanks @michaelbrewer for the quick fix. I've pushed a change before merging so customers receive a warning that this is not necessary (double serialization), and link to this issue. |
Thank you. I actually think I found a use case: @logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP)
@event_source(data_class=APIGatewayProxyEventV2)
def lambda_handler(event: APIGatewayProxyEventV2, context: LambdaContext):
logger.append_keys(path=event.path)
return app.resolve(event, context) Of course there are other ways to solve this, instead of using the event source handler 😏 |
Yes within |
This is now released under 1.25.10 version! |
Expected Behaviour
Using the event source decorator with APIGatewayProxyEventV2 will run Lambda function and not fail with TypeError
Current Behaviour
When activating debug mode through either
APIGatewayHttpResolver(debug=True)
orPOWERTOOLS_EVENT_HANDLER_DEBUG=true
causesTypeError: Object of type APIGatewayProxyEventV2 is not JSON serializable
and no further debug entries get logged.Code snippet
Possible Solution
Workaround: Enable debug mode and comment event source out
Steps to Reproduce
Create a Lambda function accepting APIGatewayProxyEventV2 requests. Decorate the handler method with logger inject and event source and add a simple route that will just return a small JSON response. Then enable debug mode by one of the supported ways and watch the lambda function fail
AWS Lambda Powertools for Python version
latest (Layer version 18)
AWS Lambda function runtime
3.9
Packaging format used
Lambda Layers
Debugging logs
The text was updated successfully, but these errors were encountered: