全部產品
Search
文件中心

Resource Orchestration Service:Fn::And

更新時間:Jun 19, 2024

調用內建函式Fn::And代表AND運算子,最少包含兩個條件。如果所有指定條件計算為true,則返回true;如果任意條件計算為false,則返回false。

函式宣告

  • JSON

    {
      "Fn::And": [
        "condition1",
        "condition2",
        ...
      ]
    }
  • YAML

    • 完整函數的文法。

      Fn::And:
        - condition1
        - condition2
        - ...
    • 縮寫形式。

      !And [condition1, condition2, ...]

參數資訊

condition:計算為true或false的條件。

傳回值

true或false。

使用樣本

您可以在Conditions中使用Fn::And定義一個條件。

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  EnvType:
    Default: pre
    Type: String
Conditions:
  TestEqualsCond:
    !Equals
      - prod
      - !Ref EnvType
  TestAndCond:
    !And
      - TestEqualsCond
      - !Equals
          - pre
          - !Ref EnvType
{
  "Parameters": {
    "EnvType": {
      "Default": "pre",
      "Type": "String"
    }
  },
  "Conditions": {
    "TestEqualsCond": {
      "Fn::Equals": [
        "prod",
        {"Ref": "EnvType"}
      ]
    },
    "TestAndCond": {
      "Fn::And": [
        "TestEqualsCond",
        {
          "Fn::Equals": [
            "pre",
            {"Ref": "EnvType"}
          ]
        }
      ]
    }
  }
}

支援的函數