Publishing to a topic
You can publish a single SMS message to many phone numbers at once by subscribing those phone numbers to an Amazon SNS topic. An SNS topic is a communication channel to which you can add subscribers and then publish messages to all of those subscribers. A subscriber receives all messages published to the topic until you cancel the subscription, or until the subscriber opts out of receiving SMS messages from your Amazon account.
Sending a message to a topic (console)
To create a topic
Complete the following steps if you don't already have a topic to which you want to send SMS messages.
Sign in to the Amazon SNS console
. -
In the console menu, choose an Amazon Region that supports SMS messaging.
-
In the navigation pane, choose Topics.
-
On the Topics page, choose Create topic.
-
On the Create topic page, under Details, do the following:
-
For Type, choose Standard.
-
For Name, enter a topic name.
-
(Optional) For Display name, enter a custom prefix for your SMS messages. When you send a message to the topic, Amazon SNS prepends the display name followed by a right angle bracket (>) and a space. Display names are not case sensitive, and Amazon SNS converts display names to uppercase characters. For example, if the display name of a topic is
MyTopic
and the message isHello World!
, the message appears as:MYTOPIC> Hello World!
-
-
Choose Create topic. The topic's name and Amazon Resource Name (ARN) appear on the Topics page.
To create an SMS subscription
You can use subscriptions to send an SMS message to multiple recipients by publishing the message only once to your topic.
When you start using Amazon SNS to send SMS messages, your Amazon account is in the SMS sandbox. The SMS sandbox provides a safe environment for you to try Amazon SNS features without risking your reputation as an SMS sender. While your account is in the SMS sandbox, you can use all of the features of Amazon SNS, but you can send SMS messages only to verified destination phone numbers. For more information, see SMS sandbox.
Sign in to the Amazon SNS console
. -
In the navigation pane, choose Subscriptions.
-
On the Subscriptions page, choose Create subscription.
-
On the Create subscription page, under Details, do the following:
-
For Topic ARN, enter or choose the Amazon Resource Name (ARN) of the topic to which you want to send SMS messages.
-
For Protocol, choose SMS.
-
For Endpoint, enter the phone number that you want to subscribe to your topic.
-
-
Choose Create subscription. The subscription information appears on the Subscriptions page.
To add more phone numbers, repeat these steps. You can also add other types of subscriptions, such as email.
To send a message
When you publish a message to a topic, Amazon SNS attempts to deliver that message to every phone number that is subscribed to the topic.
-
In the Amazon SNS console
, on the Topics page, choose the name of the topic to which you want to send SMS messages. -
On the topic details page, choose Publish message.
-
On the Publish message to topic page, under Message details, do the following:
-
For Subject, keep the field blank unless your topic contains email subscriptions and you want to publish to both email and SMS subscriptions. Amazon SNS uses the Subject that you enter as the email subject line.
-
(Optional) For Time to Live (TTL), enter a number of seconds that Amazon SNS has to send your SMS message to any mobile application endpoint subscribers.
-
-
Under Message body, do the following:
-
For Message structure, choose Identical payload for all delivery protocols to send the same message to all protocol types subscribed to your topic. Or, choose Custom payload for each delivery protocol to customize the message for subscribers of different protocol types. For example, you can enter a default message for phone number subscribers and a custom message for email subscribers.
-
For Message body to send to the endpoint, enter your message, or your custom messages per delivery protocol.
If your topic has a display name, Amazon SNS adds it to the message, which increases the message length. The display name length is the number of characters in the name plus two characters for the right angle bracket (>) and the space that Amazon SNS adds.
For information about the size quotas for SMS messages, see Publishing to a mobile phone.
-
-
(Optional) For Message attributes, add message metadata such as timestamps, signatures, and IDs.
-
Choose Publish message. Amazon SNS sends the SMS message and displays a success message.
Sending a message to a topic (Amazon SDKs)
To use an Amazon SDK, you must configure it with your credentials. For more information, see The shared config and credentials files in the Amazon SDKs and Tools Reference Guide.
The following code example shows how to:
Create an Amazon SNS topic.
Subscribe phone numbers to the topic.
Publish SMS messages to the topic so that all subscribed phone numbers receive the message at once.