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

Sending an SMS Message

You can use Amazon SNS to send SMS messages to SMS-enabled devices. You can publish messages directly to the phone numbers for these devices, and you do not need to subscribe the phone numbers to an Amazon SNS topic.

Subscribing phone numbers to a topic can be still useful if you want to publish each message to multiple phone numbers at once. For steps on how to publish an SMS message to a topic, see Sending an SMS Message to Multiple Phone Numbers.

When you send a message, you can control whether the message is optimized for cost or reliable delivery, and you can specify a sender ID. If you send the message programmatically by using the Amazon SNS API or AWS SDKs, you can specify a maximum price for the message delivery.

Each SMS message can contain up to 140 bytes, and the character limit depends on the encoding scheme. For example, an SMS message can contain:

  • 160 GSM characters

  • 140 ASCII characters

  • 70 UCS-2 characters

If you publish a message that exceeds the size limit, Amazon SNS sends it as multiple messages, each fitting within the size limit. Messages are not cut off in the middle of a word but on whole-word boundaries. The total size limit for a single SMS publish action is 1600 bytes.

When you send an SMS message, specify the phone number using the E.164 format. E.164 is a standard for the phone number structure used for international telecommunication. Phone numbers that follow this format can have a maximum of 15 digits, and they are prefixed with the plus character (+) and the country code. For example, a U.S. phone number in E.164 format would appear as +1XXX5550100.

Sending a Message (Console)

  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 Send a text message (SMS). The Send text message (SMS) window opens.

  5. For Message type, choose one of the following:

    • Promotional – Noncritical messages, such as marketing messages. Amazon SNS optimizes the message delivery to incur the lowest cost.

    • Transactional – Critical messages that support customer transactions, such as one-time passcodes for multi-factor authentication. Amazon SNS optimizes the message delivery to achieve the highest reliability.

    This message-level setting overrides your default message type, which you set on the Text messaging preferences page.

    For pricing information for promotional and transactional messages, see Global SMS Pricing.

  6. For Number, type the phone number to which you want to send the message.

  7. For Message, type the message to send.

  8. (Optional) For Sender ID, type a custom ID that contains up to 11 alphanumeric characters, including at least one letter and no spaces. The sender ID is displayed as the message sender on the receiving device. For example, you can use your business brand to make the message source easier to recognize.

    Support for sender IDs varies by country. For example, messages delivered to U.S. phone numbers will not display the sender ID. For the countries that support sender IDs, see Supported Regions and Countries.

    If you do not specify a sender ID, the message will display a long code as the sender ID in supported countries. For countries that require an alphabetic sender ID, the message displays NOTICE as the sender ID.

    This message-level sender ID overrides your default sender ID, which you set on the Text messaging preferences page.

  9. Choose Send text message.

Sending a Message (AWS SDKs)

To send an SMS message by using one of AWS SDKs, use the action in that SDK that corresponds to the Publish request in the Amazon SNS API. With this request, you can send an SMS message directly to a phone number. You can also use the MessageAttributes parameter to set values for the following attribute names:

AWS.SNS.SMS.SenderID

A custom ID that contains up to 11 alphanumeric characters, including at least one letter and no spaces. The sender ID is displayed as the message sender on the receiving device. For example, you can use your business brand to make the message source easier to recognize.

Support for sender IDs varies by country. For example, messages delivered to U.S. phone numbers will not display the sender ID. For the countries that support sender IDs, see Supported Regions and Countries.

If you do not specify a sender ID, the message will display a long code as the sender ID in supported countries. For countries that require an alphabetic sender ID, the message displays NOTICE as the sender ID.

This message-level attribute overrides the account-level attribute DefaultSenderID, which you set by using the SetSMSAttributes request.

AWS.SNS.SMS.MaxPrice

The maximum amount in USD that you are willing to spend to send the SMS message. Amazon SNS will not send the message if it determines that doing so would incur a cost that exceeds the maximum price.

This attribute has no effect if your month-to-date SMS costs have already exceeded the limit set for the MonthlySpendLimit attribute, which you set by using the SetSMSAttributes request.

If you are sending the message to an Amazon SNS topic, the maximum price applies to each message delivery to each phone number that is subscribed to the topic.

AWS.SNS.SMS.SMSType

The type of message that you are sending:

  • Promotional (default) – Noncritical messages, such as marketing messages. Amazon SNS optimizes the message delivery to incur the lowest cost.

  • Transactional – Critical messages that support customer transactions, such as one-time passcodes for multi-factor authentication. Amazon SNS optimizes the message delivery to achieve the highest reliability.

This message-level attribute overrides the account-level attribute DefaultSMSType, which you set by using the SetSMSAttributes request.

(Optional) Setting Message Attributes (AWS SDK for Java)

You set message attribute values by constructing a map that associates the attribute keys with MessageAttributeValue objects. Each MessageAttributeValue object is initialized with an attribute value, and each object declares the data type for the value. The following example sets the sender ID to "mySenderID", maximum price to 0.50 USD, and SMS type to promotional:

Copy
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>(); smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue() .withStringValue("mySenderID") //The sender ID shown on the device. .withDataType("String")); smsAttributes.put("AWS.SNS.SMS.MaxPrice", new MessageAttributeValue() .withStringValue("0.50") //Sets the max price to 0.50 USD. .withDataType("Number")); smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue() .withStringValue("Promotional") //Sets the type to promotional. .withDataType("String"));

When you send an SMS message, you will apply your attributes to the PublishRequest object.

Sending a Message (AWS SDK for Java)

The following example uses the publish method of the AmazonSNSClient class to send a message directly to a phone number:

Copy
public static void main(String[] args) { AmazonSNSClient snsClient = new AmazonSNSClient(); String message = "My SMS message"; String phoneNumber = "+1XXX5550100"; Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>(); //<set SMS attributes> sendSMSMessage(snsClient, message, phoneNumber, smsAttributes); } public static void sendSMSMessage(AmazonSNSClient snsClient, String message, String phoneNumber, Map<String, MessageAttributeValue> smsAttributes) { PublishResult result = snsClient.publish(new PublishRequest() .withMessage(message) .withPhoneNumber(phoneNumber) .withMessageAttributes(smsAttributes)); System.out.println(result); // Prints the message ID. }

When you run this example, the message ID is displayed in the console output window of your IDE:

Copy
{MessageId: 9b888f80-15f7-5c30-81a2-c4511a3f5229}