All Products
Search
Document Center

Resource Orchestration Service:Fn::And

Last Updated:Mar 15, 2024

The built-in function Fn::And represents the AND operator and must contain at least two conditions. If all the specified conditions are evaluated as true, true is returned. If a condition is evaluated as false, false is returned.

Declaration

  • JSON

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

    • Syntax for the full function name:

      Fn::And:
        - condition1
        - condition2
        - ...
    • Syntax for the short form:

      !And [condition1, condition2, ...]

Parameters

condition: the condition that you want to evaluate.

Return value

true or false.

Examples

In the following examples, the Fn::And function is used to define a condition in the Conditions section:

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

Supported functions