我可以在cftemplate格式中将fn :: join放入fn :: if语句中吗

时间:2019-01-22 11:14:27

标签: amazon-web-services aws-lambda amazon-cloudformation devops aws-cloud-config

我遇到的情况是,我的应用程序部署在不同的环境(产品和阶段)中。 我有一个带有以下参数的通用cftemplate.json

"Parameters" : {
    "EnvType" : {
      "Description" : "Environment type.",
      "Default" : "test",
      "Type" : "String",
      "AllowedValues" : ["prod", "stage"],
      "ConstraintDescription" : "must specify prod or test."
    }
  },

  "Conditions" : {
    "CreateProdResources" : {"Fn::Equals" : [{"Ref" : "EnvType"}, "prod"]}
  },

现在我有警报了,

"AppServerHealthCheckAlarm":{
     "Type":"AWS::CloudWatch::Alarm",
     "Properties":{
        "AlarmName" : {"Fn::Join" : ["", [
           {"Ref" : "AppId"}, ",",
           {"Ref" : "AppServerAG"}, ":", "HealthCheck", ",", "MAJOR"]]},
 ------
 ------
 ------
  }
},

现在,我想将此fn :: join放在fn :: if条件内,以便于prod应该是主要的,对于stage应该是minor的。

我应该如何配置

1 个答案:

答案 0 :(得分:0)

我认为与其将Fn::Join包装在Fn::If内,反而更好。这应该可以正常工作:

{
    "AlarmName":
    {"Fn::Join": ["",
                  [{"Ref" : "AppId"},
                   ",",
                   {"Ref" : "AppServerAG"},
                   ":",
                   "HealthCheck",
                   ",",
                   {"Fn::If": ["CreateProdResources", "MAJOR", "MINOR"]}
                  ]
    ]}
}