Skip to content

ApiGatewayResolver root routes and strip_prefixes #646

Closed
@BVMiko

Description

@BVMiko

I ran into an issue when using a route with the rule "/" along with strip_prefixes feature. This rule is unable to trigger due to the path variable being reduced down to an empty string instead of a forward slash.

from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
app = ApiGatewayResolver(strip_prefixes=["/some-path"])
@app.get('/')
def my_func():
    return {'execution_status':'success'}

Expected Behavior

Accessing domain.com/some-path would execute my_func().

Current Behavior

Accessing domain.com/some-path returns a 404. Of note though, accessing domain.com/some-path/ (note the trailing slash) will execute my_func().

Possible Solution

Add an conditional here which will map an empty string to "/".

Steps to Reproduce (for bugs)

  1. Set up the code example above
  2. Set up ApiGateway to use a custom domain, and bind the Lambda to a custom path of some-path
  3. Visit https://CUSTOMDOMAIN/some-path and https://CUSTOMDOMAIN/some-path/ and note the different results

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions