2016-12-15 81 views
0

我試圖創建使用Fn :: GetAtt內在功能的條件塊,但它與下面的錯誤而失敗 -AWS CloudFormation條件使用FN :: GetAtt失敗

「模板驗證錯誤:模板格式錯誤:無法解析的依賴關係。無法引用模板的「條件」塊中的資源。「

My condition - 
"SomeCondition":{ 
     "Fn::Equals":[ 
      { 
       "Fn::GetAtt":[ 
        "CustomResource", 
        "ID" 
       ] 
      }, 
      "SOME-UUID" 
     ] 
    } 

有人可以爲此提出一種解決方法嗎?我想使用該條件在我的用戶數據部分中動態選擇一個腳本。

+0

什麼CustomResource的反應是什麼樣子?它有'ID'嗎? –

回答

1

的「不能引用資源模板的條件塊」錯誤消息Condition Functions文檔中解釋說:

Note

You can only reference other conditions and values from the Parameters and Mappings sections of a template. For example, you can reference a value from an input parameter, but you cannot reference the logical ID of a resource in a condition.

至於在您的用戶數據部分中動態地選擇腳本解決方法,您可以直接從移動您的CloudFormation條件邏輯到用戶數據的腳本,例如,使用Bash conditional constructFn::Sub intrinsic function

UserData: 
    "Fn::Base64": 
    !Sub | 
     #!/bin/bash -xe 
     if [[ ${CustomResource.ID} == "SOME-UUID" ]]; then 
     # some commands 
     else 
     # other commands 
     fi 
相關問題