简体   繁体   English

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

[英]CloudFormation: How to use AWS::AccountId in Mappings?

I have a mapping that looks like this: 我有一个看起来像这样的映射:

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

And I'd like to retrieve my variables by AccountId, but this doesn't get past the "validation" step 而且我想通过AccountId检索变量,但这不会超出“验证”步骤

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

Error is 错误是

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

The goal is to have some configuration driven by the account (hence environment) this is run under. 目标是使某些配置由运行该帐户的帐户(因此环境)驱动。 And I can't seem to use the accountId as the key in the mapping, otherwise AWS isn't happy because it doesn't contain alphanumeric chars 而且我似乎无法使用accountId作为映射中的键,否则AWS不满意,因为它不包含字母数字字符

Change the map to: 将地图更改为:

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

and use !Ref instead of !Sub : 并使用!Ref代替!Sub

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

Use FN::Join to prepend "aws" string to account ID if that's required further down the stack. 如果需要在堆栈中进一步使用,请使用FN :: Join将“ aws”字符串添加到帐户ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM