python - How can i send sms notification to 200 phone number and subscribe them to a topic in SNS
问题描述
Hi Guys I have a use case:
I am a broker and post a load. When I post a load all the carriers in my fav list should receive an SMS stating "NEw Load".
I was checking through the Docs available, but couldn't find anything solid.
Steps:
- Create a topic.
- Add a subscription of the phone number to the topic. 3.Publish to the topic.
I am able to create a topic:
import boto3
sns = boto3.client('sns')
response = sns.create_topic(Name='my-topic')
I am able to publish to the topic:
response = sns.publish(
TopicArn='arn:aws:sns:region:0123456789:my-topic-arn',
Message='Hello World!',
)
The issue I am stuck with is creating the subscription to the topic with multiple phone numbers.
response = client.subscribe(
TopicArn='string',
Protocol='string',
Endpoint='string',
Attributes={
'string': 'string'
},
ReturnSubscriptionArn=True|False
)
I don't see if we can have multiple phone numbers subscribed to the topic.
Is there a provision to do this?
解决方案
Based on the comments.
SNS subscribe method creates a subscription for a single phone number. There is no API call to perform bulk subscriptions.
However, one can use basic loop in python to create multiple subscriptions for a list of phone numbers.
If there is uncertainty of how subscribe
arguments should be set, one can create a test subscription in AWS console, and then use list_subscriptions_by_topic to check what is the correct form of arguments for subscribe
method.
推荐阅读
- select - 即使列在主键中,Cassandra Select 查询返回也允许过滤
- c# - 如何写入统一游戏的控制台(构建后)?
- windows - 任务计划程序:如何在输出文件的命名中使用 cmd 脚本?
- data-structures - 树的深度与高度
- javascript - 如果 onsubmit 函数运行时间超过 10 秒,HTML 表单会提交两次
- python - Google Cloud Function Build timeout - 所有要求均已加载
- azure - Azure App Service 和 .NET Core 3.1 中长时间运行计算的适当解决方案?
- powerbi - Power BI - 处理数据集中的数据时出错
- pycharm - 如何在 Pycharm 中操作两个分别为不同 Terraform 工作区配置的终端窗口?
- react-native - 为什么我不能使用钩子状态在 TextInput 中再次编辑文本?