2016-08-17 89 views
0

在我cloudformation模板我有一個參數,可以爲空,但與FN ::加入假設值,這是例子:Cloudformation與OpsWorks處理空值

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

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

如果ConfigureRecipe是空的,Cloudfomation會傳遞給OpsWorks配方「myChefRecipe ::」,並在配置啓動時給我一個錯誤,因爲一個好的變量是「myChefRecipe :: mysql」。我如何處理這個問題?如果ConfigureRecipe爲空,也許使用AWS :: NoValue。

回答

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" } ] ] } ]] 
    }