Skip to content

Bug: AppSync Events wildcard route matches channels sharing a segment prefix #8545

Closed

Description

@LemonCondor

Expected Behaviour

With handlers on /default/* and /default/users/*, a publish to /default/usersettings should be handled by /default/*, because usersettings is not inside the users segment.

Current Behaviour

/default/usersettings is routed to the /default/users/* handler. Channels like /default/users-archive/1 are routed there too.

find_best_route (event_handler/events_appsync/functions.py) turns a trailing [^/]+ into .* with pattern[:-6] + ".*". "[^/]+" is only 5 characters, so the preceding / is cut as well. /default/users/* becomes ^/default/users.*$ instead of the ^/default/users/.*$ documented in the function's docstring. It then wins over /default/* as the more specific route.

Code snippet

from aws_lambda_powertools.event_handler import AppSyncEventsResolver
from aws_lambda_powertools.event_handler.events_appsync.functions import find_best_route

app = AppSyncEventsResolver()

@app.on_publish("/default/*")
def generic(payload):
    return {"handler": "generic"}

@app.on_publish("/default/users/*")
def users(payload):
    return {"handler": "users"}

print(find_best_route({"/default/*": 1, "/default/users/*": 1}, "/default/usersettings"))
# prints "/default/users/*", expected "/default/*"

Possible Solution

Strip only the wildcard: pattern[: -len("[^/]+")] + ".*". I have a fix with regression tests ready and can open a PR.

Steps to Reproduce

Run the snippet above. Publishing an event to /default/usersettings through app.resolve(...) returns {"handler": "users"}.

Powertools for AWS Lambda (Python) version

latest (develop, 3.35.0)

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

Activity

  1. boring-cyborg commented on Oct 13, 2026

    @boring-cyborg

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

  2. powertools-for-aws-oss-automation commented on Oct 13, 2026

    @powertools-for-aws-oss-automation

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out our GitHub Discussions: Join the conversation

  3. powertools-for-aws-oss-automation commented on Oct 15, 2026

    @powertools-for-aws-oss-automation

    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 reopen the issue, or open a new issue referencing this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  4. github-actions commented on Oct 22, 2026

    @github-actions
    Contributor

    This is now released under 3.37.0 version!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions