使用OpsWorks的Cloudformation处理空值

时间:2016-08-17 14:24:33

标签: json amazon-cloudformation aws-opsworks

在我的cloudformation模板中,我有一个可以为空的参数但是Fn :: Join假设一个值,这就是示例:

 "Parameters": {
  "ConfigureRecipe": {
   "Description": "Configure recipe.",
   "Type": "String"
  }

"Configure": [ { "Fn::Join": [ "", [ "myChefRecipe::", { "Ref": "ConfigureRecipe" } ] ] } ]

如果ConfigureRecipe为空,Cloudfomation会将配方“myChefRecipe ::”传递给OpsWorks,并在配置启动时给出错误,因为一个好的变量是“myChefRecipe :: mysql”。我怎么能处理这个?如果ConfigureRecipe为空,可能使用AWS :: NoValue。

1 个答案:

答案 0 :(得分:0)

也许你可以尝试一下:

    "Parameters": {
    "ConfigureRecipe": {
    "Description": "Configure recipe.",
    "Type": "String"
    }

   "Conditions" : {
"CreateLayerWithoutRecipie" : {"Fn::Not" : [{"Ref" : "ConfigureRecipe"}]}
    },

    "Layer":{
     "Type":"AWS::OpsWorks::Layer",
     ....
     ....
     ....
     "Configure": [ "Fn::If" : [ "CreateLayerWithoutRecipie", {"Ref" : "AWS::NoValue"}, { "Fn::Join": [ "", [ "myChefRecipe::", { "Ref": "ConfigureRecipe" }  ] ] } ]]
     }