CloudFormation:如何在映射中使用AWS :: AccountId?

Ste*_*ane 3 yaml amazon-web-services aws-cloudformation

我有一个看起来像这样的映射:

Mappings:
  AccountToParams:
    aws-1234567890:
      sshSecurityGroup: sg-abcedf12
Run Code Online (Sandbox Code Playgroud)

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

SecurityGroups:
    - !FindInMap [AccountToParams, !Sub "aws-${AWS::AccountId}", sshSecurityGroup]
Run Code Online (Sandbox Code Playgroud)

错误是

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
Run Code Online (Sandbox Code Playgroud)

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

Raf*_*Raf 5

将地图更改为:

Mappings:
  AccountToParams:
    "1234567890":
      sshSecurityGroup: sg-abcedf12
Run Code Online (Sandbox Code Playgroud)

并使用!Ref代替!Sub

SecurityGroupIds:
    - !FindInMap [AccountToParams, !Ref "AWS::AccountId", sshSecurityGroup]
Run Code Online (Sandbox Code Playgroud)

使用FN :: Join将“ aws”字符串添加到帐户ID的前面,如果这在堆栈中更进一步需要的话。