javaamazon-web-servicessmsamazon-sns

how to subscribe a list of phone numbers to a aws-sns topic


I need to send 200 sms messages, and looking in the amazon documentation I found how to do this by subscribing to a topic but only one by one.

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);
}

Is there any way I send a list of phone numbers to the endpoint, or I subscribe a list of SubscribeRequest?


Solution

  • Currently, you cannot pass a list of phone numbers as an endpoint when you create subscription for a SNS Topic. Each subscription can have only ONE phone number as an endpoint.

    For emails, we can just provide the group email-id, and the email server will handle the distribution list. But something similar is not possible for phone numbers. As far as SNS is concerned, it needs a single endpoint for a selected protocol(SMS/EMAIL).

    Just to simplify things, what you do is you can maintain a list for the phone numbers in your code. You can loop through the list and call the subscribeToTopic method each time with the same topic ARN but different phone number. But I am sure you would have thought about this yourself.