Error resolving path in Api Gateway event handler
See original GitHub issueSuppose one has two routes to delete resources like the following:
Use Case 1:
Route in handler
@app.delete("/accounts/<account_id>")
def delete_account(account_id: str) -> None:
Request
{
"path": "/accounts/123",
"httpMethod": "DELETE",
"requestContext": {"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"}, # correlation ID
}
Use Case 2:
@app.delete("/accounts/<account_id>/source_networks")
def delete_source_networks(account_id: str) -> Account:
Request
{
"path": "/accounts/123/source_networks"
"httpMethod": "DELETE",
"requestContext": {"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"}, # correlation ID
}
Expected Behavior
Expected behavior is that account_id equals 123 in both use cases
Current Behavior
For use case 1 resolver calls the right function and sets account_id = 123 For use case 2, resolver calls the function of use case 1 and sets accound_id = 123/source_networks
Possible Solution
Not sure if this is actually the expected behavior of proxy integration with its greedy regexp or a bug in Lambda Power Tools
Environment
Power Tools version 1.17.1
delete_source_networks_event = {'body': '{"networks": ["172.217.0.0/16", "8.8.8.8"]}', 'httpMethod': 'DELETE', 'path': **'/accounts/123/source_networks'**, ...}
{"level":"INFO","location":"delete:209","message":"Account deleted","timestamp":"2021-07-11 15:12:42,205-0300","service":"admin_api","cold_start":false,"function_name":"FUNCTION_NAME","function_memory_size":1024,"function_arn":"INVOKED_FUNCTION_ARN","function_request_id":"AWS_REQUEST_ID","correlation_id":"c6af9ac6-7b61-11e6-9a41-93e8deadbeef",**"account_id":"123/source_networks"**,"tax_id":"123","service_id":3}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Fix the Most Common API Gateway Request Errors - Dashbird
Solving errors in the cloud isn't always straightforward, and API Gateway isn't an exception ... Handling API Gateway 400 Error: Bad Request.
Read more >Resolve API Gateway REST API Lambda integration errors
When I invoke my AWS Lambda function using an Amazon API Gateway REST API, I get an "Invalid permissions on Lambda function" error....
Read more >AWS Lambda - Getting path parameters using Node.js
Short answer: const { id } = event.pathParameters;. I recently released a short training video that demonstrates in detail how to create API...
Read more >REST API - Lambda Powertools Python - Open Source at AWS
Event handler for Amazon API Gateway REST/HTTP APIs and Application ... where we have two separate functions to resolve two paths: /hello ....
Read more >Error handling in API Gateway and AWS Lambda - Jayway
The ability to give our clients comprehensive and well defined errors when something goes wrong is just as important as as our “happy...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’re working on some MyPy fixes and as soon as I complete #517 we’ll release it OR the documentation for the new Feature Toggles utility #https://github.com/awslabs/aws-lambda-powertools-python/pull/494
ETA next Friday if all goes well
@michaelbrewer could you look into it as discussed?
@marcioemiranda as a workaround until we fix it, you could change the order of the function definition for the longest/nested being the first one.
For example: