简体   繁体   中英

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: abc@abc.com
      Protocol: email
      Endpoint: xyz@xyz.com
      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!

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: abc@abc.com
      Protocol: email
       TopicArn: !Ref Topic

 EmailSubscription2:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: xyz@xyz.com
      Protocol: email
      TopicArn: !Ref Topic

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"
EmailSubscription: 
  Type: AWS::SNS::Topic
  Properties: 
    Subscription: 
      - Endpoint: "xyz@xyz.com"
        Protocol: "email"
      - Endpoint: "abc@abc.com"
        Protocol: "email"
    TopicName: !Ref Topic                                                            

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM