Amazon Simple Notification Service

2016/06/28 - Amazon Simple Notification Service - 5 new 1 updated api methods

OptInPhoneNumber (new) Link ¶

Use this request to opt in a phone number that is opted out, which enables you to resume sending SMS messages to the number.

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

Request Syntax

client.opt_in_phone_number(
    phoneNumber='string'
)
type phoneNumber

string

param phoneNumber

[REQUIRED]

The phone number to opt in.

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

    The response for the OptInPhoneNumber action.

ListPhoneNumbersOptedOut (new) Link ¶

Returns a list of phone numbers that are opted out, meaning you cannot send SMS messages to them.

The results for ListPhoneNumbersOptedOut are paginated, and each page returns up to 100 phone numbers. If additional phone numbers are available after the first page of results, then a NextToken string will be returned. To receive the next page, you call ListPhoneNumbersOptedOut again using the NextToken string received from the previous call. When there are no more records to return, NextToken will be null.

Request Syntax

client.list_phone_numbers_opted_out(
    nextToken='string'
)
type nextToken

string

param nextToken

A NextToken string is used when you call the ListPhoneNumbersOptedOut action to retrieve additional records that are available after the first page of results.

rtype

dict

returns

Response Syntax

{
    'phoneNumbers': [
        'string',
    ],
    'nextToken': 'string'
}

Response Structure

  • (dict) --

    The response from the ListPhoneNumbersOptedOut action.

    • phoneNumbers (list) --

      A list of phone numbers that are opted out of receiving SMS messages. The list is paginated, and each page can contain up to 100 phone numbers.

      • (string) --

    • nextToken (string) --

      A NextToken string is returned when you call the ListPhoneNumbersOptedOut action if additional records are available after the first page of results.

SetSMSAttributes (new) Link ¶

Use this request to set the default settings for sending SMS messages and receiving daily SMS usage reports.

You can override some of these settings for a single message when you use the Publish action with the MessageAttributes.entry.N parameter. For more information, see Sending an SMS Message in the Amazon SNS Developer Guide .

Request Syntax

client.set_sms_attributes(
    attributes={
        'string': 'string'
    }
)
type attributes

dict

param attributes

[REQUIRED]

The default settings for sending SMS messages from your account. You can set values for the following attribute names:

MonthlySpendLimit – The maximum amount in USD that you are willing to spend each month to send SMS messages. When Amazon SNS determines that sending an SMS message would incur a cost that exceeds this limit, it stops sending SMS messages within minutes.

Warning

Amazon SNS stops sending SMS messages within minutes of the limit being crossed. During that interval, if you continue to send SMS messages, you will incur costs that exceed your limit.

DeliveryStatusIAMRole – The ARN of the IAM role that allows Amazon SNS to write logs about SMS deliveries in CloudWatch Logs. For each SMS message that you send, Amazon SNS writes a log that includes the message price, the success or failure status, the reason for failure (if the message failed), the message dwell time, and other information.

DeliveryStatusSuccessSamplingRate – The percentage of successful SMS deliveries for which Amazon SNS will write logs in CloudWatch Logs. The value can be an integer from 0 - 100. For example, to write logs only for failed deliveries, set this value to 0 . To write logs for 10% of your successful deliveries, set it to 10 .

DefaultSenderID – A string, such as your business brand, that is displayed as the sender on the receiving device. Support for sender IDs varies by country. The sender ID can be 1 - 11 alphanumeric characters, and it must contain at least one letter.

DefaultSMSType – The type of SMS message that you will send by default. You can assign the following values:

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

  • Transactional – (Default) 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.

UsageReportS3Bucket – The name of the Amazon S3 bucket to receive daily SMS usage reports from Amazon SNS. Each day, Amazon SNS will deliver a usage report as a CSV file to the bucket. The report includes the following information for each SMS message that was successfully delivered by your account:

  • Time that the message was published (in UTC)

  • Message ID

  • Destination phone number

  • Message type

  • Delivery status

  • Message price (in USD)

  • Part number (a message is split into multiple parts if it is too long for a single message)

  • Total number of parts

To receive the report, the bucket must have a policy that allows the Amazon SNS service principle to perform the s3:PutObject and s3:GetBucketLocation actions.

For an example bucket policy and usage report, see Viewing Statistics About SMS Message Delivery in the Amazon SNS Developer Guide .

  • (string) --

    • (string) --

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

    The response for the SetSMSAttributes action.

CheckIfPhoneNumberIsOptedOut (new) Link ¶

Accepts a phone number and indicates whether the phone holder has opted out of receiving SMS messages from your account. You cannot send SMS messages to a number that is opted out.

To resume sending messages, you can opt in the number by using the OptInPhoneNumber action.

Request Syntax

client.check_if_phone_number_is_opted_out(
    phoneNumber='string'
)
type phoneNumber

string

param phoneNumber

[REQUIRED]

The phone number for which you want to check the opt out status.

rtype

dict

returns

Response Syntax

{
    'isOptedOut': True|False
}

Response Structure

  • (dict) --

    The response from the CheckIfPhoneNumberIsOptedOut action.

    • isOptedOut (boolean) --

      Indicates whether the phone number is opted out:

      • true – The phone number is opted out, meaning you cannot publish SMS messages to it.

      • false – The phone number is opted in, meaning you can publish SMS messages to it.

GetSMSAttributes (new) Link ¶

Returns the settings for sending SMS messages from your account.

These settings are set with the SetSMSAttributes action.

Request Syntax

client.get_sms_attributes(
    attributes=[
        'string',
    ]
)
type attributes

list

param attributes

A list of the individual attribute names, such as MonthlySpendLimit , for which you want values.

For all attribute names, see SetSMSAttributes .

If you don't use this parameter, Amazon SNS returns all SMS attributes.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'attributes': {
        'string': 'string'
    }
}

Response Structure

  • (dict) --

    The response from the GetSMSAttributes request.

    • attributes (dict) --

      The SMS attribute names and their values.

      • (string) --

        • (string) --

Publish (updated) Link ¶
Changes (request)
{'PhoneNumber': 'string'}

Sends a message to all of a topic's subscribed endpoints. When a messageId is returned, the message has been saved and Amazon SNS will attempt to deliver it to the topic's subscribers shortly. The format of the outgoing message to each subscribed endpoint depends on the notification protocol.

To use the Publish action for sending a message to a mobile endpoint, such as an app on a Kindle device or mobile phone, you must specify the EndpointArn for the TargetArn parameter. The EndpointArn is returned when making a call with the CreatePlatformEndpoint action. The second example below shows a request and response for publishing to a mobile endpoint.

For more information about formatting messages, see Send Custom Platform-Specific Payloads in Messages to Mobile Devices .

Request Syntax

client.publish(
    TopicArn='string',
    TargetArn='string',
    PhoneNumber='string',
    Message='string',
    Subject='string',
    MessageStructure='string',
    MessageAttributes={
        'string': {
            'DataType': 'string',
            'StringValue': 'string',
            'BinaryValue': b'bytes'
        }
    }
)
type TopicArn

string

param TopicArn

The topic you want to publish to.

If you don't specify a value for the TopicArn parameter, you must specify a value for the PhoneNumber or TargetArn parameters.

type TargetArn

string

param TargetArn

Either TopicArn or EndpointArn, but not both.

If you don't specify a value for the TargetArn parameter, you must specify a value for the PhoneNumber or TopicArn parameters.

type PhoneNumber

string

param PhoneNumber

The phone number to which you want to deliver an SMS message. Use E.164 format.

If you don't specify a value for the PhoneNumber parameter, you must specify a value for the TargetArn or TopicArn parameters.

type Message

string

param Message

[REQUIRED]

The message you want to send to the topic.

If you want to send the same message to all transport protocols, include the text of the message as a String value.

If you want to send different messages for each transport protocol, set the value of the MessageStructure parameter to json and use a JSON object for the Message parameter. See the Examples section for the format of the JSON object.

Constraints: Messages must be UTF-8 encoded strings at most 256 KB in size (262144 bytes, not 262144 characters).

JSON-specific constraints:

  • Keys in the JSON object that correspond to supported transport protocols must have simple JSON string values.

  • The values will be parsed (unescaped) before they are used in outgoing messages.

  • Outbound notifications are JSON encoded (meaning that the characters will be reescaped for sending).

  • Values have a minimum length of 0 (the empty string, "", is allowed).

  • Values have a maximum length bounded by the overall message size (so, including multiple protocols may limit message sizes).

  • Non-string values will cause the key to be ignored.

  • Keys that do not correspond to supported transport protocols are ignored.

  • Duplicate keys are not allowed.

  • Failure to parse or validate any key or value in the message will cause the Publish call to return an error (no partial delivery).

type Subject

string

param Subject

Optional parameter to be used as the "Subject" line when the message is delivered to email endpoints. This field will also be included, if present, in the standard JSON messages delivered to other endpoints.

Constraints: Subjects must be ASCII text that begins with a letter, number, or punctuation mark; must not include line breaks or control characters; and must be less than 100 characters long.

type MessageStructure

string

param MessageStructure

Set MessageStructure to json if you want to send a different message for each protocol. For example, using one publish action, you can send a short message to your SMS subscribers and a longer message to your email subscribers. If you set MessageStructure to json , the value of the Message parameter must:

  • be a syntactically valid JSON object; and

  • contain at least a top-level JSON key of "default" with a value that is a string.

You can define other top-level keys that define the message you want to send to a specific transport protocol (e.g., "http").

For information about sending different messages for each protocol using the AWS Management Console, go to Create Different Messages for Each Protocol in the Amazon Simple Notification Service Getting Started Guide .

Valid value: json

type MessageAttributes

dict

param MessageAttributes

Message attributes for Publish action.

  • (string) --

    • (dict) --

      The user-specified message attribute value. For string data types, the value attribute has the same restrictions on the content as the message body. For more information, see Publish .

      Name, type, and value must not be empty or null. In addition, the message body should not be empty or null. All parts of the message attribute, including name, type, and value, are included in the message size restriction, which is currently 256 KB (262,144 bytes). For more information, see Using Amazon SNS Message Attributes .

      • DataType (string) -- [REQUIRED]

        Amazon SNS supports the following logical data types: String, Number, and Binary. For more information, see Message Attribute Data Types .

      • StringValue (string) --

        Strings are Unicode with UTF8 binary encoding. For a list of code values, see http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters .

      • BinaryValue (bytes) --

        Binary type attributes can store any binary data, for example, compressed data, encrypted data, or images.

rtype

dict

returns

Response Syntax

{
    'MessageId': 'string'
}

Response Structure

  • (dict) --

    Response for Publish action.

    • MessageId (string) --

      Unique identifier assigned to the published message.

      Length Constraint: Maximum 100 characters