簡體   English   中英

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

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

我有一個看起來像這樣的映射:

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不滿意,因為它不包含字母數字字符

將地圖更改為:

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

並使用!Ref代替!Sub

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

如果需要在堆棧中進一步使用,請使用FN :: Join將“ aws”字符串添加到帳戶ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM