Skip to content

fix(event_handler): match AppSync Events wildcard routes on segment boundaries - #8546

Open
LemonCondor wants to merge 1 commit into
aws-powertools:developfrom
LemonCondor:fix/appsync-events-wildcard-segment-boundary
Open

LemonCondor wants to merge 1 commit into
aws-powertools:developfrom
LemonCondor:fix/appsync-events-wildcard-segment-boundary

Conversation

@LemonCondor

Copy link
Copy Markdown

Issue number: closes #8545

Summary

Changes

find_best_route turned a trailing [^/]+ into .* with pattern[:-6]. "[^/]+" is 5 characters, so the / before it was dropped too: /default/users/* became ^/default/users.*$. This PR strips only the wildcard, so the regex is ^/default/users/.*$, as the docstring already describes. It also fixes the docstring example for /default/v1/*.

Tests:

  • a functional test in test_appsync_events_resolvers.py, which publishes to /default/usersettings with handlers on /default/* and /default/users/*;
  • a unit test for find_best_route in test_functions.py.

Without the fix both fail. With the fix, the appsync events unit and functional tests pass.

User experience

Before: publishing to /default/usersettings (or /default/users-archive/1) ran the /default/users/* handler.
After: it runs the /default/* handler. Channels under /default/users/... still go to /default/users/*.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…oundaries

find_best_route() turned a trailing "/*" into ".*" by slicing six
characters off "[^/]+", which also removed the preceding "/". A route
such as "/default/users/*" was compiled to ^/default/users.*$ and matched
"/default/usersettings", so that channel was dispatched to the more
specific but wrong handler instead of "/default/*".

Strip only the wildcard pattern so the separator is kept.
@LemonCondor
LemonCondor requested a review from a team as a code owner October 13, 2026 09:17
@LemonCondor
LemonCondor requested a review from hjgraca October 13, 2026 09:17
@boring-cyborg

boring-cyborg Bot commented Oct 13, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 13, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

event_handlers size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant