Created
February 27, 2022 21:09
-
-
Save ystoneman/6bafcb995960b623cf8ef6b512ce8bcc to your computer and use it in GitHub Desktop.
An example of how you can conditionally create resources in CloudFormation using Fn::If or !If for short.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Parameters: | |
SnsTopicArn: | |
Type: String | |
Default: '' | |
Description: >- | |
A pre-existing SNS topic to send S3 notifications to. | |
If not provided, a new topic will be created. | |
MyEmail: | |
Type: String | |
Description: The email address where you want to receive messages. | |
Conditions: | |
SnsTopicNotProvided: !Equals [!Ref SnsTopicArn, ''] | |
Resources: | |
MyTopic: | |
Condition: SnsTopicNotProvided | |
Type: 'AWS::SNS::Topic' | |
MySubscription: | |
Type: AWS::SNS::Subscription | |
Properties: | |
Endpoint: !Ref MyEmail | |
Protocol: email | |
TopicArn: !If [SnsTopicNotProvided, !Ref MyTopic, !Ref SnsTopicArn] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment