Skip to content

Bug: APIGatewayAuthorizerResponse allow_route do not support /{proxy+} resource #7979

@mLetrone

Description

@mLetrone

Expected Behaviour

Allowing route with a resource /{proxy+} should not produce this error:
Invalid resource path: /{proxy+}. Path should match ^[/.a-zA-Z0-9-_\\*]+$

policy.allow_route(http_method="GET", resource="/{proxy+}")
# No error raised

Current Behaviour

Currently a ValueError is raised when passing "/{proxy+}" at

Code snippet

@event_source(data_class=APIGatewayAuthorizerRequestEvent)
def lambda_handler(event: APIGatewayAuthorizerRequestEvent, _context: LambdaContext) -> dict[str, Any]:
        arn = event.method_arn
        policy = APIGatewayAuthorizerResponse.from_route_arn(
            arn=arn,
            principal_id="user",
        )
        # with event.resource = "/{proxy+}"
        policy.allow_route(http_method=event.http_method, resource=event.resource)
        return policy.asdict()

Possible Solution

Modify the regex pattern affected to path_regex inside APIGatewayAuthorizerResponse class definition to accept the value /{proxy+}.

It can be passed to r"^([/.a-zA-Z0-9-_\*]+)|(\{proxy\+\})$" as example.

Steps to Reproduce

No special installation steps are required. I can reproduce the error with the latest release (3.24.0)

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions