Skip to content

APIGatewayRestResolver route matching order #2439

Closed

Description

@royassis

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

Activity

  1. added
    bugSomething isn't working
    triagePending triage from maintainers
    on Jun 12, 2023
  2. royassis commented on Jun 12, 2023

    @royassis
    ContributorAuthor

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

  3. github-actions commented on Jun 12, 2023

    @github-actions
    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.

  4. royassis commented on Jun 12, 2023

    @royassis
    ContributorAuthor

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

  5. rubenfonseca commented on Jun 14, 2023

    @rubenfonseca
    Contributor

    Looking at this now

  6. self-assigned this
    on Jun 14, 2023
  7. rubenfonseca commented on Jun 14, 2023

    @rubenfonseca
    Contributor

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

  8. heitorlessa commented on Jun 14, 2023

    @heitorlessa
    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

  9. royassis commented on Jun 14, 2023

    @royassis
    ContributorAuthor

    Hey @heitorlessa I can workaround it for now 👍

  10. github-actions commented on Jun 14, 2023

    @github-actions
    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.

  11. github-actions commented on Jun 16, 2023

    @github-actions
    Contributor

    This is now released under 2.17.0 version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions