如何通过 CLI 订阅具有多个电子邮件地址的 SNS 主题?
单一订阅进展顺利,如下所示
aws sns subscribe --topic-arn arn:aws:sns:ap-southeast-2:nnnnnn:abcd --protocol email --notification-endpoint [email protected]
当我尝试使用(或空格)提交多封电子邮件时,它不起作用。可以吗?
同样的你,我用两行 CLI 和两封电子邮件解决了 示例:
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]
有一个关于为此提供自定义资源的 AWS 文档,但我发现他们的自定义资源不起作用...我能够通过使用类似于以下内容的 python 脚本来规避该问题:
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)
对我来说效果很好(MyEmails.txt 每行都有一个地址)。很确定 python 子进程的默认行为是等待进程完成,这样我就不用担心 aws 过载。我想我会发帖以防任何脚本小子正在努力帮助自己,并对一次手动订阅每个地址的前景感到遗憾。