The task that I need to do is make CDN depend on a S3 bucket. But we want to make it use the existing bucket rather than creating a new one.
Here is the sample code
For yaml users, you can also use:
Conditions:
CreateConfigRecorder: !Equals [ !Ref ConfigRecorderExists, 'false' ]
Resource:
#my 1st AWS Resource
ConfigRecorder:
Condition: CreateConfigRecorder
Type: AWS::Config::ConfigurationRecorder
*more codes below*
#added, since DependsOn: !If is not possible, trigger by WaitCondition if CreateConfigRecorder is true
#Hacks: https://garbe.io/blog/2017/07/17/cloudformation-hacks/
ConfigRecorderWaitHandle:
Condition: CreateConfigRecorder
DependsOn: ConfigRecorder
Type: "AWS::CloudFormation::WaitConditionHandle"
#added, since DependsOn: !If is not possible, trigger by WaitCondition if CreateConfigRecorder is false
WaitHandle:
Type: "AWS::CloudFormation::WaitConditionHandle"
#added, since DependsOn: !If is not possible
WaitCondition:
Type: "AWS::CloudFormation::WaitCondition"
Properties:
Handle: !If [CreateConfigRecorder, !Ref ConfigRecorderWaitHandle, !Ref WaitHandle]
Timeout: "1"
Count: 0
#my 2nd AWS Resource that requires DependsOn Attribute
AWSConfigRule:
Type: AWS::Config::ConfigRule
DependsOn: WaitCondition #added, since DependsOn: !If is not possible
*more codes below*
Basically my 2nd resource only has DependsOn attribute if my 1st resource is non-existent, before running the CFN. I got this from: https://garbe.io/blog/2017/07/17/cloudformation-hacks/