-
Notifications
You must be signed in to change notification settings - Fork 429
EventParser APIGatewayProxyEventModel body cannot be none #797
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
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hey @bb-rrogers, that's awesome to hear you're finding it useful! Would you have a sample event for us to test it? IIRC, API Gateway sends an empty body string when there is none, for example a typical Because I see you're using an extra middleware to control the response + using JSON dump, I think you might prefer using our API Gateway Event Handler instead to solve this and many other common developer experience issues. https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/ Example from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
tracer = Tracer()
logger = Logger()
app = ApiGatewayResolver() # by default API Gateway REST API (v1)
@app.get("/hello")
@tracer.capture_method
def get_hello_universe():
return {"message": "hello universe"}
# You can continue to use other utilities just as before
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@tracer.capture_lambda_handler
def lambda_handler(event, context):
return app.resolve(event, context) |
Hello @heitorlessa, Thanks for getting back so quickly, firstly what are you wanting in regards to a sample event. I simply set up a aws proxy lambda against an apigateway and hit it using a GET request with Postman with no request body without any modifications. As to your suggestion regarding API Gateway Event Handler. I looked at this but it seemed to more more orientated to a simple lambda handling multiple endpoints were we actually use multiple lambdas with a common layer on top. If you think we should go down the right of a API Event Handler then I could investigate further but I imagine this might still be the same problem. Also I will highlight that we are looking at maybe doing body transformation with a custom lambda integration in the future but are investigating how to handle errors nicely it seems all errors need to be json encoded in the error Message which takes away the benefit of lambda not containing api related code. Any thoughts or suggestions would be greatly appreciated. |
I see. It definitely looks like a bug to be investigated - no need to share a sample event that your Functions received. As for the use case, I can ask more questions on what this common top layer would look like later, then I can make suggestions on how to maybe make this easier and more easily maintainable, e.g cross-cutting concerns for before/after request and error handling?) |
Hey @heitorlessa - Just to be clear is there anymore information I need to give here for this bug? I'm not quite sure. |
No @bb-rrogers. We'll setup a sample infrastructure to test whether we can hit the same issue -- if we can't, we will ask |
@bb-rrogers just merged the fix for API GW v1, and also found the same bug in v2, including Query Strings key which are omitted in the payload when using API GW HTTP API v2 payload. Should be out early next week as part of the next release. |
Thanks a bunch @heitorlessa |
hey @bb-rrogers this is now out as part of 1.22.0 release - available on PyPi, SAR, and soon Lambda Layer (version 4). https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v1.22.0 |
Hello @heitorlessa, I noticed that there might still be a bug there as discussed here. Specifically, |
First time user of AWS Lambda PowerTools and I would just like to say this looks like an amazing library.
I recently came across what I think might be a bug, but not sure. When creating a simple lambda with a APIGatewayProxyEventModel being parsed it throws an error unless I put a request body in my payload. This is due to the body object being None while the model expects a "str".
This issue affects me because it makes it a body a requirement for every request.
Expected Behavior
It should execute as expected with body being an object that can be independently parsed.
Current Behavior
When invoking the Steps to Reproduce code I get the following in CloudWatch. As such the current behavior is that if body is a None object it will fail validation.
Possible Solution
Make body an optional object.
Steps to Reproduce (for bugs)
Simple Code should help you reproduce it:
Environment
The text was updated successfully, but these errors were encountered: