Closed
Description
What were you trying to accomplish?
API Gateway with a Lambda Authorizer.
Path is /name/{proxy+}
.
Allowing the route requested in the policy using APIGatewayAuthorizerResponse
:
# APIGatewayAuthorizerTokenEvent
event_arn = event.parsed_arn
authorizer_policy = APIGatewayAuthorizerResponse(...)
authorizer_policy.allow_route(
http_method=event_arn.http_method, resource=event_arn.resource
)
authorizer_policy.asdict()
Expected Behavior
The policy contains the correct resource path and can be returned to API Gateway.
Current Behavior
The resource is blank which causes this error to be thrown:
[ERROR] ValueError: Invalid resource path: . Path should match ^[/.a-zA-Z0-9-_\*]+$
I tracked it down to this line:
I don't know what the reason was for a hard check on the length of the parts for the path. @michaelbrewer could you share some light there?
Possible Solution
This issue is resolved with the following modification:
def alt_parse_api_gateway_arn(arn: str) -> APIGatewayRouteArn:
"""Parses a gateway route arn as a APIGatewayRouteArn class
Parameters
----------
arn : str
ARN string for a methodArn or a routeArn
Returns
-------
APIGatewayRouteArn
"""
arn_parts = arn.split(":")
api_gateway_arn_parts = arn_parts[5].split("/")
return APIGatewayRouteArn(
region=arn_parts[3],
aws_account_id=arn_parts[4],
api_id=api_gateway_arn_parts[0],
stage=api_gateway_arn_parts[1],
http_method=api_gateway_arn_parts[2],
resource="/".join(api_gateway_arn_parts[3:]) if len(api_gateway_arn_parts) >= 4 else "",
)
Steps to Reproduce (for bugs)
Create a proxy resource and setup a Lambda Authorizer using Powertools as described above.
Environment
- Powertools version used: 1.25.1
- Packaging format (Layers, PyPi): Both
- AWS Lambda function runtime: Python 3.9