Skip to content

Commit 62fa81f

Browse files
feat(event_source): add support for dynamic partitions in the Api Gateway Authorizer event (#2176)
Co-authored-by: Leandro Damascena <[email protected]>
1 parent acd4a89 commit 62fa81f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def __init__(
2121
stage: str,
2222
http_method: str,
2323
resource: str,
24+
partition: str = "aws",
2425
):
25-
self.partition = "aws"
26+
self.partition = partition
2627
self.region = region
2728
self.aws_account_id = aws_account_id
2829
self.api_id = api_id
@@ -55,6 +56,7 @@ def parse_api_gateway_arn(arn: str) -> APIGatewayRouteArn:
5556
arn_parts = arn.split(":")
5657
api_gateway_arn_parts = arn_parts[5].split("/")
5758
return APIGatewayRouteArn(
59+
partition=arn_parts[1],
5860
region=arn_parts[3],
5961
aws_account_id=arn_parts[4],
6062
api_id=api_gateway_arn_parts[0],
@@ -369,6 +371,7 @@ def __init__(
369371
stage: str,
370372
context: Optional[Dict] = None,
371373
usage_identifier_key: Optional[str] = None,
374+
partition: str = "aws",
372375
):
373376
"""
374377
Parameters
@@ -401,6 +404,9 @@ def __init__(
401404
If the API uses a usage plan (the apiKeySource is set to `AUTHORIZER`), the Lambda authorizer function
402405
must return one of the usage plan's API keys as the usageIdentifierKey property value.
403406
> **Note:** This only applies for REST APIs.
407+
partition: str, optional
408+
Optional, arn partition.
409+
See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
404410
"""
405411
self.principal_id = principal_id
406412
self.region = region
@@ -412,6 +418,7 @@ def __init__(
412418
self._allow_routes: List[Dict] = []
413419
self._deny_routes: List[Dict] = []
414420
self._resource_pattern = re.compile(self.path_regex)
421+
self.partition = partition
415422

416423
@staticmethod
417424
def from_route_arn(
@@ -443,7 +450,7 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
443450
raise ValueError(f"Invalid resource path: {resource}. Path should match {self.path_regex}")
444451

445452
resource_arn = APIGatewayRouteArn(
446-
self.region, self.aws_account_id, self.api_id, self.stage, http_method, resource
453+
self.region, self.aws_account_id, self.api_id, self.stage, http_method, resource, self.partition
447454
).arn
448455

449456
route = {"resourceArn": resource_arn, "conditions": conditions}

0 commit comments

Comments
 (0)