Menu
Amazon Simple Notification Service
Developer Guide (API Version 2010-03-31)

Managing Phone Numbers and SMS Subscriptions

Amazon SNS provides several options for managing who receives SMS messages from your account. With a limited frequency, you can opt in phone numbers that have opted out of receiving SMS messages from your account. To stop sending messages to SMS subscriptions, you can remove subscriptions or the topics that publish to them.

Opting Out of Receiving SMS Messages

Where required by local laws and regulations (such as the US and Canada), SMS recipients can use their devices to opt out by replying to the message with any of the following:

  • ARRET (French)

  • CANCEL

  • END

  • OPT-OUT

  • OPTOUT

  • QUIT

  • REMOVE

  • STOP

  • TD

  • UNSUBSCRIBE

To opt out, the recipient must reply to the same long code or short code that Amazon SNS used to deliver the message. After opting out, the recipient will no longer receive SMS messages delivered from your AWS account unless you opt in the phone number.

If the phone number is subscribed to an Amazon SNS topic, opting out does not remove the subscription, but SMS messages will fail to deliver to that subscription unless you opt in the phone number.

Managing Phone Numbers and Subscriptions (Console)

You can use the Amazon SNS console to control which phone numbers receive SMS messages from your account.

Opting in a Phone Number That Has Been Opted Out

You can view which phone numbers have been opted out of receiving SMS messages from your account, and you can opt in these phone numbers to resume sending messages to them.

You can opt in a phone number only once every 30 days.

  1. Sign in to the AWS Management Console and open the Amazon SNS console at https://console.aws.amazon.com/sns/v2/home.

  2. In the console menu, set the region selector to a region that supports SMS messaging.

  3. In the navigation pane, choose Text messaging (SMS).

  4. On the Text messaging (SMS) page, choose View opted out phone numbers. The Opted out phone numbers page displays the opted out phone numbers.

  5. Select the check box for the phone number that you want to opt in, and choose Opt in. The phone number is no longer opted out and will receive SMS messages that you send to it.

Deleting an SMS Subscription

Delete an SMS subscription to stop sending SMS messages to that phone number when you publish to your topics.

  1. In the navigation pane, choose Subscriptions.

  2. Select the check boxes for the subscriptions that you want to delete. Then choose Actions, and choose Delete Subscriptions.

  3. In the Delete window, choose Delete. Amazon SNS deletes the subscription and displays a success message.

Deleting a Topic

Delete a topic when you no longer want to publish messages to its subscribed endpoints.

  1. In the navigation pane, choose Topics.

  2. Select the check boxes for the topics that you want to delete. Then choose Actions, and choose Delete Topics.

  3. In the Delete window, choose Delete. Amazon SNS deletes the topic and displays a success message.

Managing Phone Numbers and Subscriptions (AWS SDKs)

You can use the AWS SDKs to make programmatic requests to Amazon SNS and manage which phone numbers can receive SMS messages from your account.

Viewing All Opted Out Phone Numbers

To view all opted out phone numbers, submit a ListPhoneNumbersOptedOut request with the Amazon SNS API. For example, using the AWS SDK for Java, you can use the listPhoneNumbersOptedOut method of the AmazonSNSClient class:

Copy
public static void main(String[] args) { AmazonSNSClient snsClient = new AmazonSNSClient(); listOptOut(snsClient); } public static void listOptOut(AmazonSNSClient snsClient) { String nextToken = null; do { ListPhoneNumbersOptedOutResult result = snsClient .listPhoneNumbersOptedOut(new ListPhoneNumbersOptedOutRequest() .withNextToken(nextToken)); nextToken = result.getNextToken(); for (String phoneNum : result.getPhoneNumbers()) { System.out.println(phoneNum); } } while (nextToken != null); }

Amazon SNS returns a paginated response, so this example repeats the request each time Amazon SNS returns a next token. When you run this example, it displays a list of all opted out phone numbers in the console output window of your IDE.

Checking Whether a Phone Number Is Opted Out

To check whether a phone number is opted out, submit a CheckIfPhoneNumberIsOptedOut request with the Amazon SNS API. For example, using the AWS SDK for Java, you can use the checkIfPhoneNumberIsOptedOut method of the AmazonSNSClient class:

Copy
CheckIfPhoneNumberIsOptedOutRequest request = new CheckIfPhoneNumberIsOptedOutRequest().withPhoneNumber(phoneNumber); System.out.println(snsClient.checkIfPhoneNumberIsOptedOut(request));

When you run this example, a true or false result is displayed in the console output window of your IDE:

Copy
{IsOptedOut: false}

Opting In a Phone Number That Has Been Opted Out

To opt in a phone number, submit an OptInPhoneNumber request with the Amazon SNS API. For example, using the AWS SDK for Java, you can use the optInPhoneNumber method of the AmazonSNSClient class:

Copy
snsClient.optInPhoneNumber(new OptInPhoneNumberRequest().withPhoneNumber(phoneNumber));

You can opt in a phone number only once every 30 days.

Deleting an SMS Subscription

To delete an SMS subscription from an Amazon SNS topic, get the subscription ARN by submitting a ListSubscriptions request with the Amazon SNS API, and then pass the ARN to an Unsubscribe request.

For example, using the AWS SDK for Java, you can get your subscription ARNs by using the listSubscriptions method of the AmazonSNSClient class:

Copy
ListSubscriptionsResult result = snsClient.listSubscriptions(); for (Subscription sub : result.getSubscriptions()) { System.out.println(sub); }

You can delete a subscription by passing its ARN as a string argument to the unsubscribe method:

Copy
snsClient.unsubscribe(subscriptionArn);

Deleting a Topic

To delete a topic and all of its subscriptions, get the topic ARN by submitting a ListTopics request with the Amazon SNS API, and then pass the ARN to the DeleteTopic request.

For example, using the AWS SDK for Java, you can get your topic ARNs by using the listTopics method of the AmazonSNSClient class:

Copy
ListTopicsResult result = snsClient.listTopics(); for (Topic t : result.getTopics()) { System.out.println(t); }

You can delete a topic by passing its ARN as a string argument to the deleteTopic method:

Copy
snsClient.deleteTopic(topicArn);