Skip to content

Commit

Permalink
chore: deal with adding new partitions for arn generation (#3571)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaythapa authored Mar 26, 2024
1 parent 53bd4e6 commit b58cebf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
24 changes: 14 additions & 10 deletions samtranslator/translator/arn_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ def _get_region_from_session() -> str:
def _region_to_partition(region: str) -> str:
# setting default partition to aws, this will be overwritten by checking the region below
region_string = region.lower()
if region_string.startswith("cn-"):
return "aws-cn"
if region_string.startswith("us-iso-"):
return "aws-iso"
if region_string.startswith("us-isob"):
return "aws-iso-b"
if region_string.startswith("us-gov"):
return "aws-us-gov"
if region_string.startswith("eu-isoe"):
return "aws-iso-e"
region_to_partition_map = {
"cn-": "aws-cn",
"us-iso-": "aws-iso",
"us-isob": "aws-iso-b",
"us-gov": "aws-us-gov",
"eu-isoe": "aws-iso-e",
}
for key, value in region_to_partition_map.items():
if region_string.startswith(key):
return value

# Using the ${AWS::Partition} placeholder so that we don't have to add new regions to the static list above
if "iso" in region_string:
return "${AWS::Partition}"

return "aws"

Expand Down
10 changes: 9 additions & 1 deletion tests/translator/test_arn_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ def setUp(self):
ArnGenerator.BOTO_SESSION_REGION_NAME = None

@parameterized.expand(
[("us-east-1", "aws"), ("cn-east-1", "aws-cn"), ("us-gov-west-1", "aws-us-gov"), ("US-EAST-1", "aws")]
[
("us-east-1", "aws"),
("cn-east-1", "aws-cn"),
("us-gov-west-1", "aws-us-gov"),
("us-isob-east-1", "aws-iso-b"),
("eu-isoe-west-1", "aws-iso-e"),
("US-EAST-1", "aws"),
("us-isof-east-1", "${AWS::Partition}"),
]
)
def test_get_partition_name(self, region, expected):
actual = ArnGenerator.get_partition_name(region)
Expand Down

0 comments on commit b58cebf

Please sign in to comment.