CloudFormation:如何在映射中使用 AWS::AccountId?
CloudFormation: How to use AWS::AccountId in Mappings?
我有一个如下所示的映射:
Mappings:
AccountToParams:
aws-1234567890:
sshSecurityGroup: sg-abcedf12
我想通过 AccountId 检索我的变量,但这不会超过 "validation" 步骤
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 不满意,因为它不包含字母数字字符
将地图更改为:
Mappings:
AccountToParams:
"1234567890":
sshSecurityGroup: sg-abcedf12
并使用 !Ref
而不是 !Sub
:
SecurityGroupIds:
- !FindInMap [AccountToParams, !Ref "AWS::AccountId", sshSecurityGroup]
如果需要进一步向下堆栈,请使用 FN::Join 将 "aws" 字符串添加到帐户 ID。
这个有效
Mappings:
AccountToParams:
"123456789012":
sshSecurityGroup: sg-abcdef12
Resources:
SecurityGroups: !FindInMap
- AccountToParams
- !Ref 'AWS::AccountId'
- sshSecurityGroup
我有一个如下所示的映射:
Mappings:
AccountToParams:
aws-1234567890:
sshSecurityGroup: sg-abcedf12
我想通过 AccountId 检索我的变量,但这不会超过 "validation" 步骤
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 不满意,因为它不包含字母数字字符
将地图更改为:
Mappings:
AccountToParams:
"1234567890":
sshSecurityGroup: sg-abcedf12
并使用 !Ref
而不是 !Sub
:
SecurityGroupIds:
- !FindInMap [AccountToParams, !Ref "AWS::AccountId", sshSecurityGroup]
如果需要进一步向下堆栈,请使用 FN::Join 将 "aws" 字符串添加到帐户 ID。
这个有效
Mappings:
AccountToParams:
"123456789012":
sshSecurityGroup: sg-abcdef12
Resources:
SecurityGroups: !FindInMap
- AccountToParams
- !Ref 'AWS::AccountId'
- sshSecurityGroup