首页 > 解决方案 > 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:

  1. Create a topic.
  2. 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?

标签: pythonamazon-web-servicespush-notificationboto3amazon-sns

解决方案


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.


推荐阅读