'Is to possible to create SNS topic with multiple email Recipients in cloudformation template?

V1: I am trying to set up a cloudwatch alarms to send email notification to the multiple team members. it looks like we can only set one email in the topic endpoint. is there any way to add list of subscribers in the endpoint in the cloudformation template? or is there any better approach to do this?

V2: when I created SNS::Subscription resource and provide 2 emails, it gave me error: ##[error]Error: Stack failed to reach update completion status, error: 'Resource is not in the state stackUpdateComplete' I am not sure if I have provided property in a right format or what could be the mistake.

Resources:
  Topic:
    Type: "AWS::SNS::Topic"
    Properties:
      DisplayName: !Sub "Connect InstanceId ${InstanceId}"

  EmailSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: [email protected]
      Protocol: email
      Endpoint: [email protected]
      Protocol: email
      TopicArn: !Ref Topic

Question: even though if it works, My question regarding to this is, what would be ideal approach when you have set up multiple CloudWatch Alarms and want to send email notification to the multiple people when certain threshold is breach? The way I see it, it is kind of defeating the purpose of re usability of cloudformation template when you hard-code every email address of users like this. and even if we parameterize email address of every users, it would take a lot of time to add email address in the parameter file when you have 50 subscribers/users. I could be wrong or is there any better approach to do this!

Thanks!



Solution 1:[1]

The CloudFormation provides a AWS::SNS::Subscription resource.

I don't see any reason why you couldn't create few of them, one for each of your email recipients.

Edit.

For two emails, you have to create two resources:

 EmailSubscription1:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: [email protected]
      Protocol: email
       TopicArn: !Ref Topic

 EmailSubscription2:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: [email protected]
      Protocol: email
      TopicArn: !Ref Topic

Solution 2:[2]

You can use

Resources:
  Topic:
    Type: "AWS::SNS::Topic"
    Properties:
      DisplayName: !Sub "Connect InstanceId ${InstanceId}"
      Subscription:
        - Endpoint: <email_1>
          Protocol: "email"
        - Endpoint: <email_2>
          Protocol: "email"

Solution 3:[3]

EmailSubscription: 
  Type: AWS::SNS::Topic
  Properties: 
    Subscription: 
      - Endpoint: "[email protected]"
        Protocol: "email"
      - Endpoint: "[email protected]"
        Protocol: "email"
    TopicName: !Ref Topic                                                            

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Sachin Roy
Solution 3 user18962534