Skip to content

APIGatewayRestResolver route matching order #2439

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

Closed
royassis opened this issue Jun 12, 2023 · 9 comments · Fixed by #2458
Closed

APIGatewayRestResolver route matching order #2439

royassis opened this issue Jun 12, 2023 · 9 comments · Fixed by #2458
Assignees
Labels
bug Something isn't working event_handlers

Comments

@royassis
Copy link
Contributor

royassis commented Jun 12, 2023

Expected Behaviour

When there are two routes:

  1. GET /studies/fetch
  2. GET /studies/{studyid}

And a request is sent to /studies/fetch, the request should be routed to the first endpoint.

Current Behaviour

Request if routed to the second endpoint.

Code snippet

from aws_lambda_powertools.event_handler import APIGatewayRestResolver

app = APIGatewayRestResolver()


@app.get("/studies/<studyid>")
def get_study(studyid):
    return "get_study"


@app.get("/studies/fetch")
def fetch_studies():
    return "fetch_studies"


def handler(event, context):
    return app.resolve(event, context)

Possible Solution

No response

Steps to Reproduce

Create a SAM project with the snippet as a lambda.
Invoke with /studies/fetch

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

Serverless Application Repository (SAR) App

Debugging logs

No response

@royassis royassis added bug Something isn't working triage Pending triage from maintainers labels Jun 12, 2023
@royassis
Copy link
Contributor Author

royassis commented Jun 12, 2023

Seems like using strip_prefixes in the init parameters like it says in the docs, resolved the issue.
Seems that I missed it.

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@royassis royassis reopened this Jun 12, 2023
@royassis
Copy link
Contributor Author

Seems that it didn't help. It might be related to the order in which the functions (with the routing decorators) are defined.

@rubenfonseca
Copy link
Contributor

Looking at this now

@rubenfonseca rubenfonseca removed the triage Pending triage from maintainers label Jun 14, 2023
@rubenfonseca rubenfonseca self-assigned this Jun 14, 2023
@rubenfonseca
Copy link
Contributor

Great finding @royassis, submitting a PR in a few minutes.

@heitorlessa
Copy link
Contributor

@rubenfonseca is controlling the release date this week but let us know if you can't workaround it now @royassis (I'd say you can given the order of registration as annoying as it is).

Thank you so much for taking valuable time to report it (everyone appreciates it!) <3

@royassis
Copy link
Contributor Author

Hey @heitorlessa I can workaround it for now 👍

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jun 14, 2023
@github-actions
Copy link
Contributor

This is now released under 2.17.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers
Projects
None yet
3 participants