suj
suj

Reputation: 529

AWS CLI SNS Subscribe with multiple email address

How to subscribe to an SNS topic with multiple email addresses via CLI ?

Single subscription is going well as given below

aws sns subscribe --topic-arn arn:aws:sns:ap-southeast-2:nnnnnn:abcd --protocol email --notification-endpoint  [email protected]

when I try to submit to multiple emails with (, or a space), it doesn't work. Is it possible?

Upvotes: 4

Views: 10888

Answers (3)

Mateo
Mateo

Reputation: 1

There was an AWS Doc regarding providing a custom resource for this but I found their custom resource to not work... I was able to circumvent the issue by using a python script akin to the following:

import sys
import subprocess

f = open("MyEmails.txt", "r")

for line in f:
    line = line.rstrip('\n')

    result = subprocess.run(["aws sns subscribe --topic-arn MY_TOPIC_ARN --protocol email --notification-endpoint " + line], shell=True, capture_output=True, text=True)
    print(result.stdout)

    

Worked perfectly for me (MyEmails.txt just had an address on each line). Pretty sure default behavior of python subprocesses is to wait until process is finished so I wouldn't worry about overloading aws. Figured I'd post in case any script kiddies were struggling to help themselves and were lamenting the prospect of manually subscribing each address one at a time.

Upvotes: 0

John Vandivier
John Vandivier

Reputation: 2426

No, it is not possible. See these two articles:

  1. Amazon takes multiple subscription endpoints as a feature request. One person notes that Google GCM API does already have this functionality.
  2. Amazon documentation notes that the current way to subscribe multiple phone numbers or emails is to create multiple subscriptions.

Upvotes: 2

Van Nguyen
Van Nguyen

Reputation: 21

The same you, I resolved with two lines Cli with two email example:

  • aws sns subscribe --topic-arn arn:aws:sns:ap-southeast-2:nnnnnn:abcd --protocol email --notification-endpoint [email protected]

  • aws sns subscribe --topic-arn arn:aws:sns:ap-southeast-2:nnnnnn:abcd --protocol email --notification-endpoint [email protected]

Upvotes: 2

Related Questions