Skip to content

Bug: include_router with a prefix ending in "/" registers "/p//x" and returns 404 #8944

Backlog

Description

@Harshil-Jani

Expected Behaviour

app.include_router(router, prefix="/p/") with a route /x should handle GET /p/x.

Current Behaviour

include_router joins the prefix and the rule with f"{prefix}{rule}", so the route is registered as /p//x. Requests to /p/x return 404.

Code snippet

from aws_lambda_powertools.event_handler import ApiGatewayResolver
from aws_lambda_powertools.event_handler.router import Router

app = ApiGatewayResolver()
router = Router()


@router.get("/x")
def x():
    return {"ok": True}


app.include_router(router, prefix="/p/")

print(app({"httpMethod": "GET", "path": "/p/x"}, {})["statusCode"])  # 404, expected 200

Possible Solution

When the rule starts with /, strip the trailing / from the prefix before joining. Rules without a leading slash (e.g. prefix="/users/" with <user_id>) keep working as today. File: aws_lambda_powertools/event_handler/api_gateway.py, include_router.

Steps to Reproduce

Run the snippet above on current develop.

I used Claude Code to help write this change; I reviewed and tested it myself.

Did you run the reproduction yourself?

Yes, I ran it and saw the failure

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Activity

  1. boring-cyborg commented on Dec 2, 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 Dec 2, 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

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