2017-06-14 20 views
3

我編譯模板,在這裏我引用Fn::Sub字符串參數時遇到很奇怪的問題,而docs也明確地說,一個可以使用的Fn::SubRef功能。這裏是一塊模板:使用編號爲FN ::子內在函數的第一個參數

"Resources": { 
    "LaunchConfiguration": { 
     "Type" : "AWS::AutoScaling::LaunchConfiguration", 
     "Properties" : { 
     "UserData": { "Fn::Base64": { "Fn::Sub": { "Ref": "UserDataParam" } } }, 

這裏是一個錯誤,我得到:

Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to specify a mapping of values to replace in the string

當我使用全符號:{ "Fn::Sub": [ { "Ref": "UserDataParam" }, {} ] },我得到完全相同的錯誤。有人有同樣的問題嗎?是否有可能避免它仍然使用參數?

+0

解釋我認爲這將是更好如果遷移到ServerFault,則提供服務。 – VillasV

回答

0

您不能在Fn :: Sub函數調用中直接使用Ref。要實現值映射,首先必須將Ref值分配給局部變量,並在Fn :: Sub字符串內使用該值。

"UserData": { 
    "Fn::Base64": { 
    "Fn::Sub": [ 
     "${variable}", 
     { 
     "variable": { 
      "Ref": "myS3Bucket" 
     } 
     }] 
    } 
} 
+1

使用這種方法,它不會替代「myS3Bucket」中的變量,我認爲這會成爲「Sub」第一個參數的主要目標。 – VillasV

相關問題