简体   繁体   中英

Negate a Condition in CloudFormation Template

I have the following condition, accordingly to that condition I create some resources, while if that condition is not met then I create other resources.

Conditions:
  ISProduction:
    "Fn::Equals":
      - !Ref Environment
      - staging
  ISNotProduction:
      "Fn::Not":
        - !Ref ISProduction

However, when I try to evaluate the template with the snippet above I get the error:

Template error: every Fn::Not object requires one boolean parameter

How can I negate a condition in a Cloud Formation Template? Or how can I use the negation of ISProduction?

I also tried the Condition below in a resource creation, but I but the template do not pass the validation because "Every Condition member must be a string".

Condition:
      "Fn::Not":
        - !Ref ISProduction

You can reference other conditions by using the Condition key before your Condition Logical ID.

Associating a Condition

To conditionally create resources, resource properties, or outputs, you must associate a condition with them. Add the Condition: key and the logical ID of the condition as an attribute to associate a condition, as shown in the following snippet. AWS CloudFormation creates the NewVolume resource only when the CreateProdResources condition evaluates to true.

Your example should look like this:

Conditions:
  ISProduction:
    "Fn::Equals":
      - !Ref Environment
      - staging
  ISNotProduction:
      "Fn::Not":
        - Condition: ISProduction

Optionally you can write it in the short form:

Conditions:
  ISProduction:
    !Equals [!Ref Environment, staging]
  ISNotProduction:
    !Not [Condition: ISProduction]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM