AWS Cloudformation - How to use If Else conditions
11,465
Define a condition in the conditions sections
Conditions:
createResource: !Equals [ !Ref 'AWS::Region', 'eu-central-1']
Then on your resources
Resources:
MyResourcesOnlyCreatedSometime:
Condition: createResource
Type: AWS::Blah::Blah
Related videos on Youtube
Author by
Elnur Mammadov
Updated on September 14, 2022Comments
-
Elnur Mammadov over 1 year
I am new to writing AWS Cloudformation templates. I am trying to use If Else conditions on my CF template. How can I use if else statements with resources?
If AWS::Region == eu-central-1 ==> create resource , else continue.
-
jarmod about 5 yearsNote to readers: you might reasonably interpret !Equals to mean "not equals" but it does not mean that. It's the YAML/CloudFormation way of saying "call the intrinsic function named Equals". If you wanted "not equals" you would have to chain both !Not and !Equals.
-
Elnur Mammadov about 5 yearsThank you for your answer. This works, only the AWS::Region must be a string ( 'AWS::Region' )
-
cementblocks about 5 yearsAh yes, that gets me every time. Edited.