Skip to content

Commit

Permalink
Do not hardcode partition if region isn't
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-k authored and markpeek committed Mar 20, 2021
1 parent b4e4008 commit 01466cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion awacs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def JSONrepr(self):
class BaseARN(AWSHelperFn):
def __init__(self, service, resource, region='', account=''):
region_string = region.lower()
if region_string.startswith("cn-"):
if region == "${AWS::Region}":
aws_partition = "${AWS::Partition}"
elif region_string.startswith("cn-"):
aws_partition = "aws-cn"
elif region_string.startswith("us-gov"):
aws_partition = "aws-us-gov"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ def test_gov(self):
self.assertEqual(
arn.JSONrepr(),
"arn:aws-us-gov:service:us-gov-west-1:account:resource")

def test_dynamic(self):
arn = BaseARN("service", "resource", "${AWS::Region}", "account")
self.assertEqual(
arn.JSONrepr(),
"arn:${AWS::Partition}:service:${AWS::Region}:account:resource")

0 comments on commit 01466cf

Please sign in to comment.