You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error resolving path in Api Gateway event handler #520
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
Hey @marcioemiranda , thanks for raising it! Could you share how you're configuring API Gateway?
At a first glance this looks like API GW route matching, so I've created this additional test for use case 2 and it works as expected --- I'm creating an API Gateway with the same path to be on the safe side and report back with a repro repo.
Test to reproduce the issue - If I define both functions with similar path in the tests it fails exactly as described
deftest_nested_dynamic_routes():
# GIVENapp=ApiGatewayResolver()
event=deepcopy(LOAD_GW_EVENT)
event["resource"] ="/accounts/{account_id}/source_networks"event["path"] ="/accounts/12345/source_networks"# first rule will be a match, hence not calling the right function# re.compile('^/accounts/(?P<account_id>.+)$')@app.get("/accounts/<account_id>")defget_lambda(account_id: str):
assertaccount_id=="12345"return {"message": f"{account_id}"}
# re.compile('^/accounts/(?P<account_id>.+)/source_networks$')@app.get("/accounts/<account_id>/source_networks")defget_lambda(account_id: str):
assertaccount_id=="12345"return {"message": f"{account_id}"}
# WHEN calling the event handlerresult=app(event, {})
# THENassertresult["statusCode"] ==200
@heitorlessa thanks for the workaround.
API gateway was provisioned by CDK => construct LambdaRestApi in '@aws-cdk/aws-apigateway'
BTW, on a different subject, I wonder when #506 will be released.
Activity
heitorlessa commentedon Jul 16, 2021
Hey @marcioemiranda , thanks for raising it! Could you share how you're configuring API Gateway?
At a first glance this looks like API GW route matching, so I've created this additional test for use case 2 and it works as expected --- I'm creating an API Gateway with the same path to be on the safe side and report back with a repro repo.
heitorlessa commentedon Jul 16, 2021
Yup, confirmed, it's a bug --- I can replicate that locally with SAM CLI
start-apitoo: https://github.com/heitorlessa/pt-issue-520Test to reproduce the issue - If I define both functions with similar path in the tests it fails exactly as described
heitorlessa commentedon Jul 16, 2021
@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:
marcioemiranda commentedon Jul 16, 2021
@heitorlessa thanks for the workaround.
API gateway was provisioned by CDK => construct LambdaRestApi in '@aws-cdk/aws-apigateway'
BTW, on a different subject, I wonder when #506 will be released.
heitorlessa commentedon Jul 16, 2021
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 ##494
ETA next Friday if all goes well
fix(api-gateway): route pattern regex aws-powertools#520
heitorlessa commentedon Jul 18, 2021
We've got a fix and will ping back once released this week @marcioemiranda ;)
If you're curious: #533
heitorlessa commentedon Jul 20, 2021
Opa @marcioemiranda - This is now available in 1.18.0
More details in the release notes: https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v1.18.0