troz troz - 1 month ago 30
YAML Question

AWS CloudFormation chaining functions

I have a template which is a Master Stack for our product. I'm in the process of changing all templates from JSON to YAML, employing the new "!if" type functionality. I originally had the troublesome part of my template look as follows (this works in JSON):

"CreateProdResources" : {"Fn::And" : [{"Fn::Not" : [{"Fn::Equals" : [{"Ref" : "Environment"}, "beta"]} ]}, {"Fn::Not" : [{"Fn::Equals" : [{"Ref" : "Environment"}, "eubeta"]} ]} ]}


I want to change this to YAML, so this portion of the template now looks like this:

CreateProdResources:
!And:
- !Not:
- !Equals:
- Ref: Environment
- beta
- !Not:
- !Equals:
- Ref: Environment
- eubeta


Cloud formation is throwing a YAML not well-formed error, because of the chained ! functions inside of a set.

Answer

To chain YAML AWS CloudFormation functions, just do as follows:

CreateProdResources:
  !And
  - !Not
    - !Equals [!Ref "Environment", "beta"]
  - !Not
    - !Equals [!Ref "Environment", "eubeta"]
Comments