From 01466cf995c4ddc88dda2c4ebb19d5149be7a847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Mon, 15 Mar 2021 11:09:13 +0100 Subject: [PATCH] Do not hardcode partition if region isn't See aws-cloudformation/cfn-python-lint#1805 --- awacs/aws.py | 4 +++- tests/test_aws.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/awacs/aws.py b/awacs/aws.py index 003ea24f..2013f374 100644 --- a/awacs/aws.py +++ b/awacs/aws.py @@ -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" diff --git a/tests/test_aws.py b/tests/test_aws.py index 38a417e9..04ae6a25 100644 --- a/tests/test_aws.py +++ b/tests/test_aws.py @@ -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")