-
Notifications
You must be signed in to change notification settings - Fork 421
Bug: API Gateway Console Test button fails validation with @event_parser because requestContext -> identity -> sourceIp value is not a valid IPv4 or IPv6 network #1562
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. |
Thank you @mikelane for flagging this issue in the API Gateway service. Would you be able to create a support case to suggest API Gateway team to use an actual IP Address in the test event? We'll cut an internal ticket to them next week. I'm removing the bug label as Parser is behaving as expected. That said, we should fix this at the source, otherwise this will happen again next time this changes to another literal we have no control over. If helpful, we keep track of real events for each event source we support here: https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/tests/events/ Have a great weekend! |
Quick update: We pinged the API Gateway team asking to fix the event in the Console; we'll revert once we hear back from them. |
I heard back from the API Gateway support team. They said this:
Someone needs to budge here 😅 |
Leave with us @mikelane. We reached out to the engineering team and will revert with an actionable plan from either side to get this resolved. This can be changed on API Gateway side. Question here is whether they have the bandwidth to do it. Worst case we disable all ip validation if that can't be honoured by the product team. Early to tell but issues like these make me reconsider our thoughts of merging Parser/Pydantic and Event Source Data Classes - I like the value Pydantic brings, but it puts us as the weakest link in contract situations like this |
The fix I've suggested will work (it does work, this is what I've done to work around the issue) and would, I think, be a better solution than disabling all ip validation. |
I hear you. I truly do. My concern here is that we're dealing with data validation - it works with an actual event. Because there is no official event source schema, there is no guarantee that tomorrow I'll wait to hear back from the API Gateway engineering team. |
Update. I have good news to share @mikelane. API Gateway Engineering team will fix the source by the end of the month - no more We'll update here when it's done and confirmed. |
Wow that's awesome! Thank you. |
Update: no update from the team on completion yet, since re:Invent is taking most of everyone's bandwidth. I'll keep you posted once that changes. |
Thanks for the update! |
Same as above ^. Sent a message to the team asking whether we can have an ETA. Thank you for your patience. |
Update: It was revealed that this fix is more impactful than initially estimated. While I still do believe that changing APIGW is the ideal route, I don't have a clear ETA at this point. I would consider altering the validation model as suggested by @mikelane as a temporary solution until APIGW testInvoke can be fixed. I'll update this thread with an ETA when possible. |
@mikelane given the elapsed time, are you still looking to use this feature in API Gateway (test button)? If you are, then happy to have a PR for this temporary fix until the permanent one is done in API Gateway, as @boivinmjc from the API Gateway team suggested. If you aren't planning to use it anymore, then I'll close it and put a reminder every quarter to check with the API Gateway team for closure. Thank you |
I am still looking for this feature in API-G, yes please. |
|
This is now released under 2.9.1 version! |
Expected Behaviour
We should be able to generate a test form the API Gateway console that allows the
ApiGatewayProxyEventModel
to be validated and parsed by Pydantic.Current Behaviour
When generating a test from the API Gateway console, the value for the
sourceIp
in requestContext -> identity is"test-invoke-source-ip"
. Since this value is defined to beIPvAnyNetwork
here, the validation fails in theevent_parser
decorator here. And so test events from the API Gateway console fail with a 502 error because of the resulting pydantic ValidationError.Code snippet
Create a lambda handler with an event parser like this...
Use the following message to the lambda:
Note the error that the sourceIp is not an IPv4 or IPv6 value.
Possible Solution
Update the sourceIp here from this:
to this:
You may want to add a test (maybe in this file?) that tests for the
'test-invoke-source-ip'
value explicitly.Note this may also be an issue with the
APIGatewayProxyEventV2Model
because of thesourceIp
definition here.Steps to Reproduce
Create the lambda function provided above. Deploy the lambda function provided above behind an api gateway. Use the api gateway console to test the function passing in the redacted_id of 12345, and
Accept:application/json
for the headers.AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: