2017-06-14 45 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

相关问题