AWS CLI cloudformation验证模板成功,但在创建堆栈时出错

时间:2020-06-25 02:15:09

标签: amazon-web-services amazon-cloudformation

美好的一天。 我在条件部分进行了更改,其中

  1. 我将Con1作为第一个条件
  2. 然后将Con2作为使用Con1的第二个

aws cloudformation validate-template中,结果是成功。 但是,当我开始通过aws cloudformation create-stack使用创建堆栈时,就会收到错误消息:

An error occurred (ValidationError) when calling the CreateStack operation: Template error: Fn::If cannot be preprocessed

这是我在“条件”部分所做的更改。

  "Conditions": {
    "Con1": {
      "Fn::Not": [{
        "Fn::Equals": [
          {"Ref": "Environment"},
          "abc"
        ]
      }]
    },
    "Con2": {
      "Fn::Not": [{
        "Fn::Equals": [
          { "Fn::If": 
            [
              "Con1", 
              { "Fn::FindInMap" : [ "iamRoles", {"Ref": "HostnameAppId"},  "abc"] },
              { "Fn::FindInMap" : [ "iamRoles", {"Ref": "HostnameAppId"},  "xyz"] }
            ]
          },
          ""]
        }]
      }
  },

2 个答案:

答案 0 :(得分:2)

尽管aws cloudformation validate-template验证不多,但是CloudFormation Linter会在部署之前发现以下问题:

E8003 Fn::Equals element must be a supported function (Ref, Fn::FindInMap, Fn::Sub, Fn::Join, Fn::Select, Fn::Split)

Visual Studio Code extension screenshot

Visual Studio Code extension可以在创作模板时内联显示这些错误

答案 1 :(得分:1)

遗憾的是,Fn::If中的不支持Conditions 。来自docs

当前,AWS CloudFormation 支持 Fn :: If内在函数的元数据属性,更新策略属性以及模板的“资源”部分和“输出”部分中的属性值。