Home > Back-end >  how to "and" two conditions together in AWS cloudformation
how to "and" two conditions together in AWS cloudformation

Time:03-02

I wish to deploy an AWS resource using cloudformation, but only in specific environments. At the top of my yaml file I have two conditions defined below, where Environment is a parameter that can take different values:

Conditions:
  notInDevelopment:
    !Not [ !Equals [!Ref Environment, development]]
  notInStaging:
    !Not [ !Equals [!Ref Environment, staging]]

When writing the AWS resource, I understand you can specify one condition like Condition: notInDevelopment, but is there a way to "AND/&&" two conditions together such that the resource is deployed when the environment is not development, and is not staging?

CodePudding user response:

Yes, CloudFormation has Fn::And. So you can do:

MyAndCondition: !And
  - !Condition notInDevelopment
  - !Condition notInStaging
  • Related