Skip to content

Bug: equal sign in path breaks lambda dynamic URL paths #1736

Closed
@baraksalomon

Description

@baraksalomon

Expected Behaviour

When having an path like: /token/bXl0b2tlbg==
And a decorator like:
@app_rest.post("/token/")
def post_token(token: str):
..

The resolve should find this function and token parameter should be populated with "bXl0b2tlbg=="

Current Behaviour

When having an path like: /token/bXl0b2tlbg==
And a decorator like:
@app_rest.post("/token/")
def post_token(token: str):
..

The resolve returns 404.

Code snippet

from aws_lambda_powertools.event_handler import APIGatewayRestResolver

app = APIGatewayRestResolver()

minimal_event = {
    "path": "/token/bXl0b2tlbg==",
    "httpMethod": "POST"
}


@app.post("/token/<token>")
def post_token(token: str):
    return {"token": token}


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


if __name__ == "__main__":
    print(lambda_handler(minimal_event, None))

Possible Solution

Didn't test it but maybe the equal sign is missing from:
SAFE_URI = "-.~()'!*:@,;" # https://www.ietf.org/rfc/rfc3986.txt

https://github.com/awslabs/aws-lambda-powertools-python/blob/118f3e995f35808cc3e4edbc70c33e6769e2506e/aws_lambda_powertools/event_handler/api_gateway.py#L43

Steps to Reproduce

Run the snipper code.
returns 404 instead of 200

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions