Skip to content

Commit 5ad6057

Browse files
fix(data_classes): support {proxy+} and path parameters in authorizer response
1 parent 7323c05 commit 5ad6057

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ class APIGatewayAuthorizerResponse:
437437
- https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
438438
"""
439439

440-
path_regex = r"^[/.a-zA-Z0-9-_\*]+$"
440+
path_regex = r"^[/.a-zA-Z0-9\-_\*\{\}\+]+$"
441441
"""The regular expression used to validate resource paths for the policy"""
442442

443443
def __init__(

tests/unit/data_classes/required_dependencies/test_api_gateway_authorizer.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,40 @@ def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuth
200200
}
201201

202202

203+
def test_authorizer_response_allow_route_with_proxy_plus(builder: APIGatewayAuthorizerResponse):
204+
builder.allow_route(http_method="GET", resource="/{proxy+}")
205+
assert builder.asdict() == {
206+
"principalId": "foo",
207+
"policyDocument": {
208+
"Version": "2012-10-17",
209+
"Statement": [
210+
{
211+
"Action": "execute-api:Invoke",
212+
"Effect": "Allow",
213+
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/GET/{proxy+}"],
214+
},
215+
],
216+
},
217+
}
218+
219+
220+
def test_authorizer_response_allow_route_with_path_parameter(builder: APIGatewayAuthorizerResponse):
221+
builder.allow_route(http_method="GET", resource="/users/{user_id}")
222+
assert builder.asdict() == {
223+
"principalId": "foo",
224+
"policyDocument": {
225+
"Version": "2012-10-17",
226+
"Statement": [
227+
{
228+
"Action": "execute-api:Invoke",
229+
"Effect": "Allow",
230+
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/GET/users/{user_id}"],
231+
},
232+
],
233+
},
234+
}
235+
236+
203237
def test_parse_api_gateway_arn_with_resource():
204238
mock_event = {
205239
"type": "TOKEN",

0 commit comments

Comments
 (0)