Skip to content

Commit b58cebf

Browse files
authored
chore: deal with adding new partitions for arn generation (#3571)
1 parent 53bd4e6 commit b58cebf

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

samtranslator/translator/arn_generator.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ def _get_region_from_session() -> str:
1717
def _region_to_partition(region: str) -> str:
1818
# setting default partition to aws, this will be overwritten by checking the region below
1919
region_string = region.lower()
20-
if region_string.startswith("cn-"):
21-
return "aws-cn"
22-
if region_string.startswith("us-iso-"):
23-
return "aws-iso"
24-
if region_string.startswith("us-isob"):
25-
return "aws-iso-b"
26-
if region_string.startswith("us-gov"):
27-
return "aws-us-gov"
28-
if region_string.startswith("eu-isoe"):
29-
return "aws-iso-e"
20+
region_to_partition_map = {
21+
"cn-": "aws-cn",
22+
"us-iso-": "aws-iso",
23+
"us-isob": "aws-iso-b",
24+
"us-gov": "aws-us-gov",
25+
"eu-isoe": "aws-iso-e",
26+
}
27+
for key, value in region_to_partition_map.items():
28+
if region_string.startswith(key):
29+
return value
30+
31+
# Using the ${AWS::Partition} placeholder so that we don't have to add new regions to the static list above
32+
if "iso" in region_string:
33+
return "${AWS::Partition}"
3034

3135
return "aws"
3236

tests/translator/test_arn_generator.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ def setUp(self):
1010
ArnGenerator.BOTO_SESSION_REGION_NAME = None
1111

1212
@parameterized.expand(
13-
[("us-east-1", "aws"), ("cn-east-1", "aws-cn"), ("us-gov-west-1", "aws-us-gov"), ("US-EAST-1", "aws")]
13+
[
14+
("us-east-1", "aws"),
15+
("cn-east-1", "aws-cn"),
16+
("us-gov-west-1", "aws-us-gov"),
17+
("us-isob-east-1", "aws-iso-b"),
18+
("eu-isoe-west-1", "aws-iso-e"),
19+
("US-EAST-1", "aws"),
20+
("us-isof-east-1", "${AWS::Partition}"),
21+
]
1422
)
1523
def test_get_partition_name(self, region, expected):
1624
actual = ArnGenerator.get_partition_name(region)

0 commit comments

Comments
 (0)