All Products
Search
Document Center

Resource Orchestration Service:Fn::And

Last Updated:Dec 19, 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

You can use Fn::And to define conditions only in the Conditions or Rules 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