CloudFormation:如何在Mappings中使用AWS :: AccountId?

时间:2017-08-16 06:37:27

标签: amazon-web-services yaml amazon-cloudformation

我的映射看起来像这样:

Mappings:
  AccountToParams:
    aws-1234567890:
      sshSecurityGroup: sg-abcedf12

我想通过AccountId检索我的变量,但这不会超过“验证”步骤

SecurityGroups:
    - !FindInMap [AccountToParams, !Sub "aws-${AWS::AccountId}", sshSecurityGroup]

错误是

16/08/2017, 16:36:18 - Template contains errors.: Template error: 
every Fn::FindInMap object requires three parameters, 
the map name, map key and the attribute for return value

目标是让一些由帐户驱动的配置(因此环境)运行。我似乎无法使用accountId作为映射中的键,否则AWS不满意,因为它不包含字母数字字符

1 个答案:

答案 0 :(得分:2)

将地图更改为:

Mappings:
  AccountToParams:
    "1234567890":
      sshSecurityGroup: sg-abcedf12

并使用!Ref代替!Sub

SecurityGroupIds:
    - !FindInMap [AccountToParams, !Ref "AWS::AccountId", sshSecurityGroup]

使用FN::Join将“aws”字符串添加到帐户ID,如果需要进一步向下堆栈。