Create AWS Resources Conditionally
Cloud Formation is a powerful tool to create and manage AWS infrastructure. There are scenarios which may demand to create resources conditionally. For example, You may need to create a role and grant read access to bucket only if user passes bucket name as parameter. But if user does not pass bucket name as parameter, then scripts should not create the role. In a simple create role script, If user won't mention resource name then script execution will fail as resource name in policy cannot be blank. Cloud Formation Conditions are very handy in such scenarios. In the following script, role creation is dependent on condition IfBucketName and this condition returns true only when value of s3BucketARN parameter is not blank. { "Conditions" : { "IfBucketName" : { "Fn::Not" : [{ "Fn::Equals" : [ "" , { "Ref" : "s3BucketARN" }]}]} }, "Resources" : { "TestRole" : {