Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deal with adding new partitions for arn generation #3571

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions samtranslator/translator/arn_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ 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

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