Search code examples
amazon-web-servicesaws-cloudformationamazon-sns

How to add email subscription of SNS Topic on CloudFormation Script?


  TestTopicSubscription:
  Type: AWS::SNS::Subscription
  Properties:
    Endpoint: [email protected]
    Protocol: email
    TopicArn: !Ref TestSnsTopic

How to add subscription for multiple email ids(eg:[email protected],[email protected]) to the above list?


Solution

  • There are no loops in CloudFormation, and AWS::SNS::Subscription does not take any lists.

    So your choices are:

    1. Use AWS CLI or SDK to programmatically create a number of stacks based on a single template. The template would be parameterized, where the parameter would be your endpoint. Thus, using bash or python, for instance, you would have to iterate over your list and create corresponding subscriptions.

    2. Creating a custom resource in CloudFormation to take your list of emails and create corresponding subscription. The resource would be in the form of a lambda function which would use AWS SDK to create needed subscriptions.

    3. Instead of custom resource, you could also create macro in CloudFormation.

    4. Manually copy-and-paste the subscriptions template, if you have only few of them in a single template.