如何将 phone 个数字的列表订阅到 aws-sns 主题
how to subscribe a list of phone numbers to a aws-sns topic
我需要发送 200 条短信,在亚马逊文档中我找到了如何通过订阅一个主题来做到这一点,但只是一个一个地订阅。
public static void main(String[] args) {
AmazonSNSClient snsClient = new AmazonSNSClient();
String phoneNumber = "+1XXX5550100";
String topicArn = createSNSTopic(snsClient);
subscribeToTopic(snsClient, topicArn, "sms", phoneNumber);
}
public static void subscribeToTopic(AmazonSNSClient snsClient, String topicArn,
String protocol, String endpoint) {
SubscribeRequest subscribe = new SubscribeRequest(topicArn, protocol,
endpoint);
SubscribeResult subscribeResult = snsClient.subscribe(subscribe);
}
有什么方法可以将 phone 号码列表发送到端点,或者我订阅 SubscribeRequest 列表?
目前,当您为 SNS 主题创建订阅时,您不能将list of phone numbers
作为端点传递。每个订阅只能有 ONE
phone 个号码作为端点。
对于邮件,我们可以只提供群组email-id,邮件服务器会处理分发列表。但是对于 phone 数字来说,类似的事情是不可能的。 As far as SNS is concerned, it needs a single endpoint for a selected protocol(SMS/EMAIL)
.
为了简化事情,您可以在代码中为 phone 数字维护一个列表。您可以遍历列表并每次使用 same topic ARN but different phone number
调用 subscribeToTopic
方法。但我相信你自己会考虑过这个问题。
我们可以使用 AWS 开发工具包将 phone 个数字的列表传递到端点。
如果您需要向多个收件人发送消息,值得阅读亚马逊的文档:(https://docs.amazonaws.cn/en_us/sns/latest/dg/sms_publish-to-topic.html) 关于发送至多个 phone 号码。
SNS 服务实现了发布-订阅模式,您可以使用它向主题发送消息。以下是完成这项工作的步骤:
- 创建一个命名主题。这只是一个通讯频道,您可以订阅 phone 个号码。
- 为您的收件人订阅主题。
- 发布关于主题的消息。
python 代码如下所示:
import boto3
# Create an SNS client
client = boto3.client(
"sns",
aws_access_key_id="YOUR ACCES KEY",
aws_secret_access_key="YOUR SECRET KEY",
region_name=us-east-1
)
# Create the topic if it doesn't exist
topic = client.create_topic(Name="invites-for-push-notifications")
topic_arn = topic['TopicArn'] # get its Amazon Resource Name
#Get List of Contacts
list_of_contacts = ["+919*********", "+917********", "+918********"]
# Add SMS Subscribers
for number in some_list_of_contacts:
client.subscribe(
TopicArn=topic_arn,
Protocol='sms',
Endpoint=number # <-- number who'll receive an SMS message.
)
# Publish a message.
client.publish(Message="Good news everyone!", TopicArn=topic_arn)
我需要发送 200 条短信,在亚马逊文档中我找到了如何通过订阅一个主题来做到这一点,但只是一个一个地订阅。
public static void main(String[] args) {
AmazonSNSClient snsClient = new AmazonSNSClient();
String phoneNumber = "+1XXX5550100";
String topicArn = createSNSTopic(snsClient);
subscribeToTopic(snsClient, topicArn, "sms", phoneNumber);
}
public static void subscribeToTopic(AmazonSNSClient snsClient, String topicArn,
String protocol, String endpoint) {
SubscribeRequest subscribe = new SubscribeRequest(topicArn, protocol,
endpoint);
SubscribeResult subscribeResult = snsClient.subscribe(subscribe);
}
有什么方法可以将 phone 号码列表发送到端点,或者我订阅 SubscribeRequest 列表?
目前,当您为 SNS 主题创建订阅时,您不能将list of phone numbers
作为端点传递。每个订阅只能有 ONE
phone 个号码作为端点。
对于邮件,我们可以只提供群组email-id,邮件服务器会处理分发列表。但是对于 phone 数字来说,类似的事情是不可能的。 As far as SNS is concerned, it needs a single endpoint for a selected protocol(SMS/EMAIL)
.
为了简化事情,您可以在代码中为 phone 数字维护一个列表。您可以遍历列表并每次使用 same topic ARN but different phone number
调用 subscribeToTopic
方法。但我相信你自己会考虑过这个问题。
我们可以使用 AWS 开发工具包将 phone 个数字的列表传递到端点。
如果您需要向多个收件人发送消息,值得阅读亚马逊的文档:(https://docs.amazonaws.cn/en_us/sns/latest/dg/sms_publish-to-topic.html) 关于发送至多个 phone 号码。
SNS 服务实现了发布-订阅模式,您可以使用它向主题发送消息。以下是完成这项工作的步骤:
- 创建一个命名主题。这只是一个通讯频道,您可以订阅 phone 个号码。
- 为您的收件人订阅主题。
- 发布关于主题的消息。
python 代码如下所示:
import boto3
# Create an SNS client
client = boto3.client(
"sns",
aws_access_key_id="YOUR ACCES KEY",
aws_secret_access_key="YOUR SECRET KEY",
region_name=us-east-1
)
# Create the topic if it doesn't exist
topic = client.create_topic(Name="invites-for-push-notifications")
topic_arn = topic['TopicArn'] # get its Amazon Resource Name
#Get List of Contacts
list_of_contacts = ["+919*********", "+917********", "+918********"]
# Add SMS Subscribers
for number in some_list_of_contacts:
client.subscribe(
TopicArn=topic_arn,
Protocol='sms',
Endpoint=number # <-- number who'll receive an SMS message.
)
# Publish a message.
client.publish(Message="Good news everyone!", TopicArn=topic_arn)