Sns DG
Sns DG
Sns DG
Service
Developer Guide
API Version 2010-03-31
Table of Contents
What is Amazon SNS? ................................................................................................................... 1
Are You a First-Time Amazon Simple Notification Service User? .................................................... 2
Beyond the getting started section .................................................................................... 2
Accessing Amazon SNS ................................................................................................. 2
Common Scenarios ............................................................................................................... 3
Fanout ......................................................................................................................... 3
Application and System Alerts ......................................................................................... 3
Push Email and Text Messaging ....................................................................................... 3
Mobile Push Notifications ................................................................................................ 3
Getting Started ............................................................................................................................. 4
Before You Begin ................................................................................................................... 4
Create a Topic ...................................................................................................................... 5
Subscribe to a Topic ............................................................................................................... 5
Publish to a Topic .................................................................................................................. 6
Create Different Messages for Each Protocol ..................................................................... 7
Clean Up ............................................................................................................................. 8
Using the SDK for Java ........................................................................................................... 8
Managing Access ........................................................................................................................ 11
Overview ............................................................................................................................ 11
When to Use Access Control ......................................................................................... 12
Key Concepts ............................................................................................................. 12
Architectural Overview .................................................................................................. 14
Using the Access Policy Language ................................................................................. 16
Evaluation Logic .......................................................................................................... 17
Example Cases for Amazon SNS Access Control .............................................................. 20
Special Information for Amazon SNS Policies ........................................................................... 25
Amazon SNS Policy Limits ............................................................................................ 25
Valid Amazon SNS Policy Actions ................................................................................... 25
Amazon SNS Keys ....................................................................................................... 26
Controlling User Access to Your AWS Account .......................................................................... 27
IAM and Amazon SNS Policies Together .......................................................................... 27
Amazon SNS ARNs ..................................................................................................... 30
Amazon SNS Actions ................................................................................................... 31
Amazon SNS Keys ....................................................................................................... 31
Example Policies for Amazon SNS .................................................................................. 32
Using Temporary Security Credentials ............................................................................. 34
Amazon SNS Mobile Push ............................................................................................................ 36
Overview ............................................................................................................................ 36
Prerequisites ...................................................................................................................... 37
Mobile Push HighLevel Steps ................................................................................................ 38
Step 1: Request Credentials from Mobile Platforms ............................................................ 38
Step 2: Request Token from Mobile Platforms ................................................................... 38
Step 3: Create Platform Application Object ....................................................................... 39
Step 4: Create Platform Endpoint Object .......................................................................... 39
Step 5: Publish Message to Mobile Endpoint .................................................................... 39
Getting Started with ADM ...................................................................................................... 39
ADM Prerequisites ....................................................................................................... 40
Step 1: Create a Kindle Fire App with the ADM Service Enabled .......................................... 40
Step 2: Obtain a Client ID and Client Secret ..................................................................... 40
Step 3: Obtain an API Key ............................................................................................. 41
Step 4: Obtain a Registration ID ..................................................................................... 41
Step 5: Sending a Message to a Kindle Fire app using Amazon SNS and ADM ...................... 42
Getting Started with APNS .................................................................................................... 44
APNS Prerequisites ..................................................................................................... 44
Step 1: Create an iOS App ............................................................................................ 45
API Version 2010-03-31
iii
45
45
46
46
47
47
49
49
50
50
51
52
56
59
63
63
67
68
68
68
69
70
72
72
73
73
73
73
73
75
76
76
76
76
76
77
78
78
80
83
88
88
88
90
91
91
92
93
93
93
94
95
96
96
97
97
171
171
172
175
175
176
178
179
181
181
183
183
185
When using Amazon SNS, you (as the owner) create a topic and control access to it by defining policies
that determine which publishers and subscribers can communicate with the topic. A publisher sends
messages to topics that they have created or to topics they have permission to publish to. Instead of
including a specific destination address in each message, a publisher sends a message to the topic.
Amazon SNS matches the topic to a list of subscribers who have subscribed to that topic, and delivers
the message to each of those subscribers. Each topic has a unique name that identifies the Amazon SNS
endpoint for publishers to post messages and subscribers to register for notifications. Subscribers receive
all messages published to the topics to which they subscribe, and all subscribers to a topic receive the
same messages.
Another way to use "fanout" is to replicate data sent to your production environment with your development
environment. Expanding upon the previous example, you could subscribe yet another queue to the same
topic for new incoming orders. Then, by attaching this new queue to your development environment, you
could continue to improve and test your application using data received from your production environment.
For more information about sending Amazon SNS messages to Amazon SQS queues, see Sending
Amazon SNS Messages to Amazon SQS Queues (p. 106). For more information about sending Amazon
SNS messages to HTTP/S endpoints, see Sending Amazon SNS Messages to HTTP/HTTPS
Endpoints (p. 127).
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
Create a Topic
Now that you're signed up for Amazon SNS, you're ready to create a topic. A topic is a communication
channel to send messages and subscribe to notifications. It provides an access point for publishers and
subscribers to communicate with each other. In this section you create a topic named MyTopic.
To create a topic
1.
2.
3.
4.
Select the new topic and then click the topic ARN.
The Topic Details page appears.
5.
Subscribe to a Topic
To receive messages published to a topic, you have to subscribe an endpoint to that topic. An endpoint
is a mobile app, web server, email address, or an Amazon SQS queue that can receive notification
messages from Amazon SNS. Once you subscribe an endpoint to a topic and the subscription is confirmed,
the endpoint will receive all messages published to that topic.
In this section you subscribe an endpoint to the topic you just created in the previous section.You configure
the subscription to send the topic messages to your email account.
To subscribe to a topic
1.
2.
3.
In the Topic ARN field, paste the topic ARN you created in the previous task, for example:
arn:aws:sns:us-west-2:111122223333:MyTopic.
4.
5.
Important
Entourage Users: Entourage strips out the confirmation URL. Type an email address you
can access in a different email application.
6.
7.
Go to your email application and open the message from AWS Notifications, and then click the link
to confirm your subscription.
Your web browser displays a confirmation response from Amazon SNS.
Publish to a Topic
Publishers send messages to topics. Once a new message is published, Amazon SNS attempts to deliver
that message to every endpoint that is subscribed to the topic. In this section you publish a message to
the email address you defined in the previous task.
To publish to a topic
1.
2.
In the left navigation pane, click Topics and then select the topic you want to publish to.
Click the Publish to topic button.
The Publish a Message page appears.
3.
4.
5.
You can now use your email application to open the message from AWS Notifications and read the
message.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select a topic.
Click the Publish to topic button.
The Publish a message page appears.
4.
5.
6.
7.
In this example for the Target Platforms, select email and sms.
Click the Generate JSON button.
In the following example, messages are specified for the default, email, and sms protocols. Do not
delete any protocols from the list.
You can now modify the message text so that it is tailored to each type of client, such as in this
example up to 140 characters for sms and up to 256Kb for email.
{
"default": "Message body text here.",
"email": "Message body text here.",
"sms": "Message body text here."
}
8.
Clean Up
You have created a topic, subscribed to it, and published a message to the topic. Now you clean up your
environment by unsubscribing from the topic and then deleting the topic.
3.
4.
2.
To delete a topic
Open the Amazon SNS console at https://console.aws.amazon.com/sns/.
1.
2.
In the left navigation pane, click Topics, and then select the topic you want to delete.
Click the Actions drop-down list and select Delete topics.
3.
you must pass with the actual request. The response object includes information returned from Amazon
SNS in response to the request.
For example, the AmazonSNSClient class provides the createTopic method to create a topic to which
notifications can be published. This method maps to the underlying CreateTopic API action. You create
a CreateTopicRequest object to pass information with the createTopic method.
The following import statements are used with the provided java samples.
import
import
import
import
import
import
import
import
import
import
com.amazonaws.services.sns.AmazonSNSClient;
com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
com.amazonaws.regions.Region;
com.amazonaws.regions.Regions;
com.amazonaws.services.sns.model.CreateTopicRequest;
com.amazonaws.services.sns.model.CreateTopicResult;
com.amazonaws.services.sns.model.SubscribeRequest;
com.amazonaws.services.sns.model.PublishRequest;
com.amazonaws.services.sns.model.PublishResult;
com.amazonaws.services.sns.model.DeleteTopicRequest;
The following example shows how to create a new Amazon SNS client, set the Amazon SNS endpoint
to use, and then create a new topic.
Note
In some of the following examples, the getCachedResponseMetadata method is used to show
how to programmatically retrieve the request ID for a previously executed successful Amazon
SNS request.This is typically used for debugging issues and is helpful when requesting assistance
from Amazon Web Services.
Create a Topic
//create a new SNS client and set endpoint
AmazonSNSClient snsClient = new AmazonSNSClient(new ClasspathPropertiesFileCre
dentialsProvider());
snsClient.setRegion(Region.getRegion(Regions.US_EAST_1));
//create a new SNS topic
CreateTopicRequest createTopicRequest = new CreateTopicRequest("MyNewTopic");
CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest);
//print TopicArn
System.out.println(createTopicResult);
//get request id for CreateTopicRequest from SNS metadata
System.out.println("CreateTopicRequest - " + snsClient.getCachedResponse
Metadata(createTopicRequest));
When you run this example, the following is displayed in the console output window of your IDE, such as
Eclipse:
{TopicArn: arn:aws:sns:us-east-1:123456789012:MyNewTopic}
CreateTopicRequest - {AWS_REQUEST_ID=93f7fc90-f131-5ca3-ab18-b741fef918b5}
The following examples show how to subscribe to, publish to, and delete a topic.
API Version 2010-03-31
9
Subscribe to a Topic
//subscribe to an SNS topic
SubscribeRequest subRequest = new SubscribeRequest(topicArn, "email",
"[email protected]");
snsClient.subscribe(subRequest);
//get request id for SubscribeRequest from SNS metadata
System.out.println("SubscribeRequest - " + snsClient.getCachedResponse
Metadata(subRequest));
System.out.println("Check your email and confirm subscription.");
When you run this example, the following is displayed in the console output window of your IDE:
SubscribeRequest - {AWS_REQUEST_ID=9b7ff59a-f917-533a-a6bd-be4bf6df0acf}
Check your email and confirm subscription.
Publish to a Topic
//publish to an SNS topic
String msg = "My text published to SNS topic with email endpoint";
PublishRequest publishRequest = new PublishRequest(topicArn, msg);
PublishResult publishResult = snsClient.publish(publishRequest);
//print MessageId of message published to SNS topic
System.out.println("MessageId - " + publishResult.getMessageId());
When you run this example, the following is displayed in the console output window of your IDE:
MessageId - 9b888f80-15f7-5c30-81a2-c4511a3f5229
Delete a Topic
//delete an SNS topic
DeleteTopicRequest deleteTopicRequest = new DeleteTopicRequest(topicArn);
snsClient.deleteTopic(deleteTopicRequest);
//get request id for DeleteTopicRequest from SNS metadata
System.out.println("DeleteTopicRequest - " + snsClient.getCachedResponse
Metadata(deleteTopicRequest));
When you run this example, the following is displayed in the console output window of your IDE:
DeleteTopicRequest - {AWS_REQUEST_ID=067a4980-4e93-5bfc-b88c-0251415bc852}
Overview
Topics
When to Use Access Control (p. 12)
Key Concepts (p. 12)
Architectural Overview (p. 14)
Using the Access Policy Language (p. 16)
Evaluation Logic (p. 17)
Example Cases for Amazon SNS Access Control (p. 20)
This section describes basic concepts you need to understand to use the access policy language to write
policies. It also describes the general process for how access control works with the access policy
language, and how policies are evaluated.
Key Concepts
The following sections describe the concepts you need to understand to use the access policy language.
They're presented in a logical order, with the first terms you need to know at the top of the list.
Permission
A permission is the concept of allowing or disallowing some kind of access to a particular resource.
Permissions essentially follow this form: "A is/isn't allowed to do B to C where D applies." For example,
Jane (A) has permission to publish (B) to TopicA (C) as long as she uses the HTTP protocol (D). Whenever
Jane publishes to TopicA, the service checks to see if she has permission and if the request satisfies the
conditions set forth in the permission.
Statement
A statement is the formal description of a single permission, written in the access policy language. You
always write a statement as part of a broader container document known as a policy (see the next concept).
Policy
A policy is a document (written in the access policy language) that acts as a container for one or more
statements. For example, a policy could have two statements in it: one that states that Jane can subscribe
using the email protocol, and another that states that Bob cannot publish to TopicA. As shown in the
following figure, an equivalent scenario would be to have two policies, one that states that Jane can
subscribe using the email protocol, and another that states that Bob cannot publish to TopicA.
Issuer
The issuer is the person who writes a policy to grant permissions for a resource. The issuer (by definition)
is always the resource owner. AWS does not permit AWS service users to create policies for resources
they don't own. If John is the resource owner, AWS authenticates John's identity when he submits the
policy he's written to grant permissions for that resource.
Principal
The principal is the person or persons who receive the permission in the policy. The principal is A in the
statement "A has permission to do B to C where D applies." In a policy, you can set the principal to
"anyone" (i.e., you can specify a wildcard to represent all people). You might do this, for example, if you
don't want to restrict access based on the actual identity of the requester, but instead on some other
identifying characteristic such as the requester's IP address.
Action
The action is the activity the principal has permission to perform. The action is B in the statement "A has
permission to do B to C where D applies." Typically, the action is just the operation in the request to AWS.
For example, Jane sends a request to Amazon SNS with Action=Subscribe. You can specify one or
multiple actions in a policy.
Resource
The resource is the object the principal is requesting access to. The resource is C in the statement "A
has permission to do B to C where D applies."
Requester
The requester is the person who sends a request to an AWS service and asks for access to a particular
resource. The requester sends a request to AWS that essentially says: "Will you allow me to do B to C
where D applies?"
Evaluation
Evaluation is the process the AWS service uses to determine if an incoming request should be denied
or allowed based on the applicable policies. For information about the evaluation logic, see Evaluation
Logic (p. 17).
Effect
The effect is the result that you want a policy statement to return at evaluation time.You specify this value
when you write the statements in a policy, and the possible values are deny and allow.
For example, you could write a policy that has a statement that denies all requests that come from
Antarctica (effect=deny given that the request uses an IP address allocated to Antarctica). Alternately,
you could write a policy that has a statement that allows all requests that don't come from Antarctica
(effect=allow, given that the request doesn't come from Antarctica). Although the two statements sound
like they do the same thing, in the access policy language logic, they are different. For more information,
see Evaluation Logic (p. 17).
Although there are only two possible values you can specify for the effect (allow or deny), there can be
three different results at policy evaluation time: default deny, allow, or explicit deny. For more information,
see the following concepts and Evaluation Logic (p. 17).
Default Deny
A default deny is the default result from a policy in the absence of an allow or explicit deny.
Allow
An allow results from a statement that has effect=allow, assuming any stated conditions are met. Example:
Allow requests if they are received before 1:00 p.m. on April 30, 2010. An allow overrides all default
denies, but never an explicit deny.
Explicit Deny
An explicit deny results from a statement that has effect=deny, assuming any stated conditions are met.
Example: Deny all requests if they are from Antarctica. Any request that comes from Antarctica will always
be denied no matter what any other policies might allow.
Architectural Overview
The following figure and table describe the main components that interact to provide access control for
your resources.
Your resources (contained within the AWS service; e.g., Amazon SQS queues).
Your policies.
Typically you have one policy per resource, although you could have multiple. The AWS service
itself provides an API you use to upload and manage your policies.
Process for Using Access Control with the Access Policy Language
1
The AWS service determines which policies are applicable to the request.
For example, Amazon SNS looks at all the available Amazon SNS policies and determines which
ones are applicable (based on what the resource is, who the requester is, etc.).
The AWS service either denies the request or continues to process it.
For example, based on the policy evaluation result, the service either returns an "Access denied"
error to the requester or continues to process the request.
Related Topics
Architectural Overview (p. 14)
Evaluation Logic
The goal at evaluation time is to decide whether a given request should be allowed or denied. The
evaluation logic follows several basic rules:
By default, all requests to use your resource coming from anyone but you are denied
An allow overrides any default denies
An explicit deny overrides any allows
The order in which the policies are evaluated is not important
The following flow chart and discussion describe in more detail how the decision is made.
The enforcement code then evaluates all the policies that are applicable to the request (based
on the resource, principal, action, and conditions).
The order in which the enforcement code evaluates the policies is not important.
In all those policies, the enforcement code looks for an explicit deny instruction that would apply
to the request.
If it finds even one, the enforcement code returns a decision of "deny" and the process is finished
(this is an explicit deny; for more information, see Explicit Deny (p. 14)).
If no explicit deny is found, the enforcement code looks for any "allow" instructions that would
apply to the request.
If it finds even one, the enforcement code returns a decision of "allow" and the process is done
(the service continues to process the request).
If no allow is found, then the final decision is "deny" (because there was no explicit deny or allow,
this is considered a default deny (for more information, see Default Deny (p. 14)).
If someone sends a request from the U.S., the condition is met (the request is not from Antarctica).
Therefore, the request is allowed. But, if someone sends a request from Antarctica, the condition isn't
met, and the policy's result is therefore a default deny.
You could turn the result into an explicit deny by rewriting the policy (named Policy A2) as in the following
diagram. Here, the policy explicitly denies a request if it comes from Antarctica.
If someone sends a request from Antarctica, the condition is met, and the policy's result is therefore an
explicit deny.
The distinction between a default deny and an explicit deny is important because a default deny can be
overridden by an allow, but an explicit deny can't. For example, let's say there's another policy that allows
requests if they arrive on June 1, 2010. How does this policy affect the overall outcome when coupled
with the policy restricting access from Antarctica? We'll compare the overall outcome when coupling the
date-based policy (we'll call Policy B) with the preceding policies A1 and A2. Scenario 1 couples Policy
A1 with Policy B, and Scenario 2 couples Policy A2 with Policy B. The following figure and discussion
show the results when a request comes in from Antarctica on June 1, 2010.
In Scenario 1, Policy A1 returns a default deny, as described earlier in this section. Policy B returns an
allow because the policy (by definition) allows requests that come in on June 1, 2010. The allow from
Policy B overrides the default deny from Policy A1, and the request is therefore allowed.
In Scenario 2, Policy B2 returns an explicit deny, as described earlier in this section. Again, Policy B
returns an allow. The explicit deny from Policy A2 overrides the allow from Policy B, and the request is
therefore denied.
Once this statement is added, the user with AWS account 1111-2222-3333 can publish messages to the
topic.
Note
Subscribe and Receive are separate actions in the policy. You can apply different conditions
to the subscriber and the message recipient.
{
"Version":"2012-10-17",
"Id":"SomePolicyId",
"Statement" :[
{
"Sid":"Statement1",
"Effect":"Allow",
"Principal" :{
"AWS":"111122223333"
},
"Action":["sns:Subscribe"],
"Resource": "arn:aws:sns:us-east-1:444455556666:MyTopic",
"Condition" :{
"StringEquals" :{
"sns:Protocol":"https"
}
}
}
]
}
This policy uses the aws:SourceArn condition to restrict access to the queue based on the source of
the message being sent to the queue. You can use this type of policy to allow Amazon SNS to send
messages to your queue only if the messages are coming from one of your own topics. In this case, you
specify a particular one of your topics, whose ARN is arn:aws:sns:us-east-1:444455556666:MyTopic.
The preceding policy is an example of the Amazon SQS policy you could write and add to a specific
queue. It would grant Amazon SNS and other AWS products access. Amazon SNS gives a default policy
to all newly created topics. The default policy gives all other AWS products access to your topic. This
default policy uses an aws:SourceArn condition to ensure that AWS products access your topic only
on behalf of AWS resources you own.
{
"Version":"2012-10-17",
"Id":"MyAWSPolicy",
"Statement" :[
{
"Sid":"My-statement-id",
"Effect":"Allow",
"Principal" :"*",
"Action":"sns:Publish",
"Resource":"arn:aws:sns:us-east-1:111122223333:My-Topic",
"Condition":{
"StringEquals":{ "AWS:SourceOwner":"444455556666" } ,
"ArnLike": {"AWS:SourceArn": "arn:aws:s3:*:*:*" }
}
}
]
}
Maximum Limit
Bytes
20 kb
Statements
20
Principals
20
Resource
Description
sns:AddPermission
sns:CreatePlatformApplication
sns:CreatePlatformEndpoint
sns:DeleteEndpoint
This grants permission to the endpoint for a device and mobile app
on one of the supported push notification services. For more information, see DeleteEndpoint in the Amazon Simple Notification Service
API Reference.
sns:DeletePlatformApplication
sns:DeleteTopic
sns:GetEndpointAttributes
Action
Description
sns:GetPlatformApplicationAttrib- This grants permission to retrieve the attributes of the platform applicutes
ation object. For more information, see GetPlatformApplicationAttributes in the Amazon Simple Notification Service API Reference.
sns:GetTopicAttributes
sns:ListEndpointsByPlatformAp- This grants permission to list the endpoints and endpoint attributes
plication
for devices and mobile apps in a supported push notification service.
For more information, see ListEndpointsByPlatformApplication in the
Amazon Simple Notification Service API Reference.
sns:ListPlatformApplications
This grants permission to list the platform application objects for the
supported push notification services. For more information, see
ListPlatformApplications in the Amazon Simple Notification Service
API Reference.
sns:ListSubscriptionsByTopic
sns:Publish
sns:Receive
sns:RemovePermission
sns:SetEndpointAttributes
sns:SetPlatformApplicationAttrib- This grants permission to set the attributes of the platform application
utes
object. For more information, see SetPlatformApplicationAttributes
in the Amazon Simple Notification Service API Reference.
sns:SetTopicAttributes
sns:Subscribe
Important
When you use a policy to control access by sns:Endpoint, be aware that DNS issues might affect
the endpoint's name resolution in the future.
Important
Using Amazon SNS with IAM doesn't change how you use Amazon SNS. There are no changes
to Amazon SNS actions, and no new Amazon SNS actions related to users and access control.
For examples of policies that cover Amazon SNS actions and resources, see Example Policies for Amazon
SNS (p. 32).
Note
The preceding example shows simple policies with no conditions. You could specify a particular
condition in either policy and get the same result.
There is one difference between AWS IAM and Amazon SNS policies: The Amazon SNS policy system
lets you grant permission to other AWS accounts, whereas the IAM policy doesn't.
It's up to you how you use both of the systems together to manage your permissions, based on your
needs. The following examples show how the two policy systems work together.
Example 1
In this example, both an IAM policy and an Amazon SNS policy apply to Bob. The IAM policy gives him
permission for Subscribe on any of the AWS account's topics, whereas the Amazon SNS policy gives
him permission to use Publish on a specific topic (topic_xyz). The following diagram illustrates the
concept.
If Bob were to send a request to subscribe to any topic in the AWS account, the IAM policy would allow
the action. If Bob were to send a request to publish a message to topic_xyz, the Amazon SNS policy
would allow the action.
Example 2
In this example, we build on example 1 (where Bob has two policies that apply to him). Let's say that Bob
publishes messages to topic_xyz that he shouldn't have, so you want to entirely remove his ability to
publish to topics. The easiest thing to do is to add an IAM policy that denies him access to the Publish
action on all topics. This third policy overrides the Amazon SNS policy that originally gave him permission
to publish to topic_xyz, because an explicit deny always overrides an allow (for more information about
policy evaluation logic, see Evaluation Logic (p. 17)). The following diagram illustrates the concept.
For examples of policies that cover Amazon SNS actions and resources, see Example Policies for Amazon
SNS (p. 32). For more information about writing Amazon SNS policies, go to the technical documentation
for Amazon SNS.
Example
Following is an ARN for a topic named my_topic in the us-east-1 region, belonging to AWS account
123456789012.
arn:aws:sns:us-east-1:123456789012:my_topic
Example
If you had a topic named my_topic in each of the different Regions that Amazon SNS supports, you could
specify the topics with the following ARN.
arn:aws:sns:*:123456789012:my_topic
You can use * and ? wildcards in the topic name. For example, the following could refer to all the topics
created by Bob that he has prefixed with bob_.
arn:aws:sns:*:123456789012:bob_*
As a convenience to you, when you create a topic, Amazon SNS returns the topic's ARN in the response.
Note
Key names are case sensitive.
Note
In the future, Amazon SNS might add new actions that should logically be included in one of the
following policies, based on the policys stated goals.
http://sns.us-east-1.amazonaws.com/
?Name=My-Topic
&Action=CreateTopic
&Signature=gfzIF53exFVdpSNb8AiwN3Lv%2FNYXh6S%2Br3yySK70oX4%3D
&SignatureVersion=2
&SignatureMethod=HmacSHA256
&Timestamp=2010-03-31T12%3A00%3A00.000Z
&SecurityToken=SecurityTokenValue
&AWSAccessKeyId=Access Key ID provided by AWS Security Token Service
Overview
You send push notification messages to both mobile devices and desktops using one of the following
supported push notification services:
The following figure shows an overview of how Amazon SNS is used to send a direct push notification
message to a mobile endpoint.
Push notification services, such as APNS and GCM, maintain a connection with each app and associated
mobile device registered to use their service. When an app and mobile device register, the push notification
API Version 2010-03-31
36
service returns a device token. Amazon SNS uses the device token to create a mobile endpoint, to which
it can send direct push notification messages. In order for Amazon SNS to communicate with the different
push notification services, you submit your push notification service credentials to Amazon SNS to be
used on your behalf. For more information, see Amazon SNS Mobile Push HighLevel Steps (p. 38)
In addition to sending direct push notification messages, you can also use Amazon SNS to send messages
to mobile endpoints subscribed to a topic. The concept is the same as subscribing other endpoint types,
such as Amazon SQS, HTTP/S, email, and SMS, to a topic, as described in What is Amazon Simple
Notification Service? (p. 1). The difference is that Amazon SNS communicates using the push notification
services in order for the subscribed mobile endpoints to receive push notification messages sent to the
topic. The following figure shows a mobile endpoint as a subscriber to an Amazon SNS topic. The mobile
endpoint communicates using push notification services where the other endpoints do not.
Prerequisites
To begin using Amazon SNS mobile push notifications, you need the following:
A set of credentials for connecting to one of the supported push notification services: ADM, APNS,
Baidu, GCM, MPNS, or WNS.
A device token or registration ID for the mobile app and device.
Amazon SNS configured to send push notification messages to the mobile endpoints.
A mobile app that is registered and configured to use one of the supported push notification services.
Registering your application with a push notification service requires several steps. Amazon SNS needs
some of the information you provide to the push notification service in order to send direct push notification
messages to the mobile endpoint. Generally speaking, you need the required credentials for connecting
to the push notification service, a device token or registration ID (representing your mobile device and
mobile app) received from the push notification service, and the mobile app registered with the push
notification service.
The exact form the credentials take differs between mobile platforms, but in every case, these credentials
must be submitted while making a connection to the platform. One set of credentials is issued for each
mobile app, and it must be used to send a message to any instance of that app.
The specific names will vary depending on which push notification service is being used. For example,
when using APNS as the push notification service, you need a device token. Alternatively, when using
API Version 2010-03-31
37
GCM, the device token equivalent is called a registration ID. The device token or registration ID is a string
that is sent to the application by the operating system of the mobile device. It uniquely identifies an instance
of a mobile app running on a particular mobile device and can be thought of as unique identifiers of this
app-device pair.
Amazon SNS stores the credentials (plus a few other settings) as a platform application resource. The
device tokens (again with some extra settings) are represented as objects called platform endpoints.
Each platform endpoint belongs to one specific platform application, and every platform endpoint can be
communicated with by using the credentials that are stored in its corresponding platform application.
The following sections include the prerequisites for each of the supported push notification services. Once
you've obtained the prerequisite information, you can send a push notification message using the AWS
Management Console or the Amazon SNS mobile push APIs. For more information, see Amazon SNS
Mobile Push HighLevel Steps (p. 38).
Step 1: Create a Kindle Fire App with the ADM Service Enabled (p. 40)
Step 2: Obtain a Client ID and Client Secret (p. 40)
Step 3: Obtain an API Key (p. 41)
Step 4: Obtain a Registration ID (p. 41)
Step 5: Sending a Push Notification Message to a Kindle Fire app using Amazon SNS and ADM (p. 42)
ADM Prerequisites
To send push notifications to a Kindle Fire app using Amazon SNS and ADM, you need the following:
Kindle Fire app with the ADM service enabled
Client ID and client secret
API key
Registration ID
If you already have these prerequisites, then you can send a push notification message to a Kindle Fire
app using either the Amazon SNS console or the Amazon SNS API. For more information about using
the Amazon SNS console, see Using Amazon SNS Mobile Push (p. 78). For more information about
using the Amazon SNS API, see Step 5: Sending a Push Notification Message to a Kindle Fire app using
Amazon SNS and ADM (p. 42)
Note
If you do not already have a Kindle Fire app registered with ADM, then you can use the
sample Kindle Fire app provided by AWS as a template to get started. For more information,
see Step 4: Obtain a Registration ID (p. 41).
4.
5.
On the Amazon App Distribution Portal, click Apps and Services, click the name of your Kindle Fire
app, and then click Device Messaging.
Verify that ADM is enabled for the app. If your app is not listed on the Amazon App Distribution Portal,
then add it and enable ADM.
On the Amazon App Distribution Portal, click Apps and Services, click the name of your Kindle Fire
app, and then click Security Profile. You should see a security profile associated with your app. If
not, click Security Profiles to create a new security profile.
2.
Click View Security Profile. Make note of the client ID and client secret.
Note
An API key is required to use ADM with pre-release or test apps. However, it is not required
with a release or production version of your app when you allow Amazon to sign your app on
your behalf.
Obtain an API key by following instructions at Getting Your OAuth Credentials and API Key.
2.
Import the KindleMobilePushApp folder into your IDE. In Eclipse, click File, Import, expand the
Android folder, click Existing Android Code Into Workspace, click Next, browse to the folder
KindleMobilePushApp, click OK, and then click Finish.
After the sample Kindle Fire app has been imported into your IDE, you need to add the API key for
your Kindle Fire app to the strings.xml file, which is included in the sample Kindle Fire app.
3.
Add the API key to the strings.xml file. In your IDE you will find the file included in the values
folder, which is a subfolder of res. You add the string to the following:
<string name="api_key"></string>
4.
Run the app to see the registration ID as output to the Android logging system. If you are using
Eclipse with the Android ADT plug-in, you can see the registration ID in the LogCat display window.
For example, the output containing the registration ID will look similar to the following:
amzn1.adm-registration.v2.Example...1cwWJUvgkcPPYcaXCpPWmG3BqnwiqIEzp5zZ7y_jsM0PKPxKhddCzx6paEsyay9Zn3D4wNUJb8m6HXrBf9dqaEw
You should now have the necessary information from ADM (client ID, client secret, API key, and registration
ID) to send push notification messages to your mobile endpoint. You can now send a push notification
message to the Kindle Fire app on your device by either using the Amazon SNS console or the Amazon
SNS API. To use the Amazon SNS console, see Using Amazon SNS Mobile Push (p. 78). To use the
Amazon SNS API, see Step 5: Sending a Push Notification Message to a Kindle Fire app using Amazon
SNS and ADM (p. 42).
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
2.
Import the SNSSamples folder to the top-level directory of the newly created Java project. In Eclipse,
right-click the name of the Java project and then click Import, expand General, click File System,
click Next, browse to the SNSSamples folder, click OK, and then click Finish.
3.
Right-click the Java project folder, click Build Path, and then click Configure Build Path...
Click the Libraries tab, and then click Add Library....
3.
Click AWS SDK for Java, click Next, and then click Finish.
2.
3.
Locate the demoKindleAppNotification method and enter the registration ID you received from
ADM for the value of the registration ID string. For example, it should look similar to the following:
String registrationId = = "amzn1.adm-registration.v2.Example...1cwWJUvgk
cPPYcaXCpPWmG3Bqn-wiqIEzp5zZ7y_jsM0PKPxKhd
dCzx6paEsyay9Zn3D4wNUJb8m6HXrBf9dqaEw";
4.
Enter the client ID for your app. For example, it should look similar to the following:
String clientId = "amzn1.application-oa2-client.EX
AMPLE7423654b79fc9f062fEXAMPLE";
5.
Enter the client secret for your app. For example, it should look similar to the following:
String clientSecret = "EXAMPLE01658e75ceb7bf9f71939647b1aa105c1c8eac
cabaf7d41f68EXAMPLE";
6.
Enter a name for your app. App names must be made up of only uppercase and lowercase ASCII
letters, numbers, underscores, hyphens, and periods, and must be between 1 and 256 characters
long. For example, it should look similar to the following:
String applicationName = "admpushapp";
7.
Run the Java application. You should see output similar to the following in the output window of your
IDE:
===========================================
Getting Started with Amazon SNS
===========================================
{PlatformApplicationArn: arn:aws:sns:us-west-2:111122223333:app/ADM/mypush
appname}
{EndpointArn: arn:aws:sns:us-west-2:111122223333:endpoint/ADM/mypushapp
name/97e9ced9-f136-3893-9d60-775467eafebb}
{"ADM": "{ \"data\": { \"message\": \"ENTER YOUR MESSAGE\" } }"}
Published. MessageId=b35fb4bz-b503-4e37-83d4-feu4218d6da6
On your Kindle Fire device, you should see a push notification message appear within the Kindle
Fire app.
APNS Prerequisites
To send push notifications to mobile devices using Amazon SNS and APNS, you need to obtain the
following:
iOS app registered with APNS
APNS SSL certificate
App private key
Device token
If you already have these prerequisites, you can send a push notification message to an iOS app using
either the Amazon SNS console or you can use the Amazon SNS API. For more information about using
the Amazon SNS console, see Using Amazon SNS Mobile Push (p. 78). For more information about
using the Amazon SNS API, see Send a push notification message to an iOS app using Amazon SNS
and APNS (p. 47).
Note
If you do not already have an iOS app registered with APNS, then you can use the sample iOS
app provided by AWS as a template to get started. For more information, see Step 5: Obtain a
Device Token (p. 46).
On the Apple Developer web site, click Member Center, click Certificates, Identifiers and Profiles,
and then click Certificates.
Select the certificate you created for iOS APNS development, click Download, and then save the
file, which will have the .cer extension type.
To convert the APNS SSL certificate from .cer format to .pem format
The following steps use the openssl utility.
At a command prompt, type the following command. Replace myapnsappcert.cer with the name
of the certificate you downloaded from the Apple Developer web site.
openssl x509 -in myapnsappcert.cer -inform DER -out myapnsappcert.pem
The newly created .pem file will be used to configure Amazon SNS for sending mobile push notification
messages.
Open Keychain Access, select Keys, and then highlight your app private key.
Click File, click Export Items..., and then enter a name in the Save As: field.
Accept the default .p12 file format and then click Save.
To convert the app private key from .p12 format to .pem format
The newly created .pem file will be used to configure Amazon SNS for sending mobile push notification
messages.
3.
4.
Run the app in Xcode. In the output window, you should see the device token displayed, which is
similar to the following:
Device Token = <examp1e 29z6j5c4 df46f809 505189c4 c83fjcgf 7f6257e9 8542d2jt
3395kj73>
Note
Do not include spaces in the device token when submitting it to Amazon SNS.
Next Steps
You should now have the necessary information from APNS (SSL certificate, app private key, and device
token) to send push notification messages to your mobile endpoint. You can now send a notification to
the iOS app on your device by either using the Amazon SNS console or the Amazon SNS API.
To send a notification to the iOS app on your device using the Amazon SNS console, see Using Amazon
SNS Mobile Push (p. 78).
To use the Amazon SNS API, see Send a push notification message to an iOS app using Amazon
SNS and APNS (p. 47).
To send a push notification message to a VoIP app using Amazon SNS and APNS, see Send a push
notification message to a VoIP iOS app using Amazon SNS and APNS (p. 49).
To send a push notification message to a Mac OS X app using Amazon SNS and APNS, see Send a
push notification message to a Mac OS X app using Amazon SNS and APNS (p. 49).
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
3.
Right-click the Java project folder, click Build Path, and then click Configure Build Path...
Click the Libraries tab, and then click Add Library....
Click AWS SDK for Java, click Next, and then click Finish.
2.
3.
Locate the demoAppleSandboxAppNotification method and enter the device token you received
from APNS for the value of the device token string. For example, it should look similar to the following:
String deviceToken = "ex
amp1e29z6j5c4df46f809505189c4c83fjcgf7f6257e98542d2jt3395kj73";
4.
Enter the APNS SSL certificate for your app. At the beginning of each new line in your certificate,
you must add \n. For example, it should look similar to the following:
String certificate = "-----BEGIN CERTIFICATE-----\nMIICiTCCAfICCQD6m7oRw0uXO
jANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC\nVVMxCzAJBgNVBAgTAldBMRAwDgY
DVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6\nb24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRI
wEAYDVQQDEwlUZXN0Q2lsYWMxHzAd\nBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcN
MTEwNDI1MjA0NTIxWhcN\nMTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAld
BMRAwDgYD\nVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSB
Db25z\nb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFt\nYX
pvbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ\n21uUSfw
fEvySWtC2XADZ4nB+BLYgVIk60CpiwsZ3G93vUEIO3IyNoH/f0wYK8m9T\nrDHu
dUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswY6786m86gpE\nIbb3OhjZn
zcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAtCu4\nnUhVVxYUnt
neD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0Fkb\nFFBjvS
fpJIlJ00zbhNYS5f6GuoEDmFJl0ZxB
HjJnyp378OD8uTs7fLvjx79LjSTb\nNYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE=\n----END CERTIFICATE-----";
5.
Enter the private key for your app. At the beginning of each new line in your certificate, you must add
\n. For example, it should look similar to the following:
String privateKey = "-----BEGIN RSA PR1VATE KEY-----\nMJICiTCHAfIC
CQD9m7oRw0uXOjANBgkqhkiG7w0BAQUFADCBiDELMAkGA1UEBhMC\nWVMxCzAJBgNVBAgTAldB
MRAwDgYDVQQHEwdTZWF0dGx2MQ8wDQYDVQQKEwZBbWF6\nVVMxCzAJBgNVBAgTAldBMRAwDgY
DVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6\n4MXNchZOFFreg4Rr3Xzhb9Rhv
lIRgsr3wU4/FYai3z96EXAMPLE=\n-----END RSA PR1VATE KEY-----";
6.
Enter a name for your app. App names must be made up of only uppercase and lowercase ASCII
letters, numbers, underscores, hyphens, and periods, and must be between 1 and 256 characters
long. For example, it should look similar to the following:
7.
Run the Java application. You should see output similar to the following in the output window of your
IDE:
===========================================
Getting Started with Amazon SNS
===========================================
{PlatformApplicationArn: arn:aws:sns:us-west-2:111122223333:app/APNS_SAND
BOX/mypushappname}
{EndpointArn: arn:aws:sns:us-west-2:111122223333:endpoint/APNS_SANDBOX/push
app/97e9ced9-f136-3893-9d60-775467eafebb}
{"default":"This is the default Message","APNS_SANDBOX":"{ \"aps\" : {
\"alert\" : \"You have got email.\", \"badge\" : 9,\"sound\" :\"default\"}}"}
Published. MessageId=d65fb4bb-b903-5e37-83d4-feb4818d6da3
Note
If you do not already have an iOS app registered with APNS, you can download and use the
snsmobilepush.zip sample file provided by AWS as a template to get started. For more information,
see Step 5: Obtain a Device Token (p. 46).
3.
4.
5.
6.
In the Push Notification Platform field, select Apple Development or Apple Production.
In the Push Certification Type field, select VoIP Push Certificate.
Select the password encrypted certificate and private key, as exported from Keychain Access on
your Mac computer in the .p12 file format.
Enter your password, and then click Create Platform Application.
Note
If you do not already have a Mac OS X app registered with APNS, you can download and use
a sample application such as PushyMac, which is available from the Apple Developer web site.
2.
3.
App names must be made up of only uppercase and lowercase ASCII letters, numbers, underscores,
hyphens, and periods, and must be between 1 and 256 characters long.
In the Push Notification Platform field, select Apple Development or Apple Production.
4.
5.
6.
Baidu Prerequisites
To send a push notification message to mobile devices using Amazon SNS and Baidu, you need the
following:
Baidu account
Registration as a Baidu developer
Baidu cloud push project
API key and secret key from a Baidu cloud push project
Baidu user ID and channel ID
Android demo app
If you already have these prerequisites, then you can send a push notification message to a mobile
endpoint using the Amazon SNS API. For more information about using the Amazon SNS API, see Step
6: Send a Push Notification Message to a Mobile Endpoint using Amazon SNS and Baidu (p. 63).
Important
In order to create a Baidu account there is a verification step where you must enter Chinese
Simplified characters. The easiest way to accomplish this task is for someone that can read
Chinese to assist. Another option is to use Amazon Mechanical Turk for creating the Baidu
account. Once you have the account and password created for Baidu, you could login and change
the password without needing to enter Chinese Simplified characters. For more information
about Mechanical Turk, see the Amazon Mechanical Turk Requester User Interface.
2.
Enter an email address, password, and verification code, and then click (Registration).
You should then see a page similar to the following, informing you that an activation email has been
sent to the email address you entered.
3.
Login to your email account, open the activation email you received from Baidu, and click the provided
link:
4.
After you click the provided link in the activation email from Baidu, you must then enter the verification
code (Chinese Simplified characters).
Once you have created a Baidu account, you can then register as a developer.
2.
3.
On the next page, near the top right corner, click (Developer Services).
4.
5.
Enter your name, description, and mobile phone number for receiving a verification text message,
and then click (Send Verification Code).
You should then receive a text message with a verification number, similar to the following:
6.
Complete the developer registration by entering the verification number and then click (Submit)
on the bottom of the page.
After registering as a Baidu developer, you can then proceed to the next step to create a Baidu cloud
push project. This assumes that you are still logged in. If you are not logged in, then you can use
the following login procedure.
To login to Baidu
1.
2.
Enter your Baidu username (email address) and password and then click (Login).
2.
3.
On the next page, near the top right corner, click (Developer Services).
4.
5.
6.
7.
8.
9.
Upon successful completion of the project, you will then see a page similar to the following with your
app ID, API Key, and Secret Key. Make note of the API key and secret key, as they will be needed
later.
Starting from the page that displays the app ID, API Key, and Secret Key, click (Cloud Push)
2.
3.
Using reverse domain name notation, enter a package name in the (App Package Name) box.
4.
5.
6.
On the Android mobile device you want to test with, scan the QR code icon using a code scanner,
such as QR Droid, to get a link to a demo app provided by Baidu.
Note
You can also download the demo app by clicking Android (Download Android Sample)
The Baidu Push Demo app is included in the downloaded PushDemo.zip package. You
can use the demo app as an example for creating your own app to use with Baidu. In addition,
the push service jar file (pushservice-4.0.0.jar) from Baidu is included in the
PushDemo.zip package. You must use the jar file from Baidu in order to create a new app.
7.
Click the link you receive after scanning the scan code. This will download the demo app provided
by Baidu onto your mobile device.
8.
After the download has completed, install the demo app onto your mobile device. You should then
see the following Push Demo app installed:
Open Push Demo and then click, in the bottom right, (Bind Without Baidu Account).
You should then see a screen similar to the following with the userId and channelId.
2.
Make a note of the userId and channelId, as you will be using them in the next step.
Note
For an example of Java code that is used to retrieve the userID and channelId, see the onBind
method in the MyPushMessageReceiver.java file of the Push Demo app from Baidu. For
more information, see the Android integration guide. To translate this guide into English, you
can paste the URL, http://developer.baidu.com/wiki/index.php?title=docs/cplat/push/guide, into
Bing Translator and then click Translate.
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
2.
Import the SNSSamples folder to the top-level directory of the newly created Java project. In Eclipse,
right-click the name of the Java project and then click Import, expand General, click File System,
click Next, browse to the SNSSamples folder, click OK, and then click Finish.
3.
Right-click the Java project folder, click Build Path, and then click Configure Build Path...
Click the Libraries tab, and then click Add Library....
3.
Click AWS SDK for Java, click Next, and then click Finish.
2.
Locate the demoBaiduAppNotification method and enter the user ID and channel ID you received
from Baidu for the value of the userId and channelId strings. For example, it should look similar to
the following:
String userId = "EXAMPLE-kLMchcX0v3xOxWVhG6TfdBp...KT2TGkvnKyTvLuS
pzK_qsHgxVB_UpmcUa7Gl6g3EXAMPLE";
String channelId = "EXAMPLE<channelId>EXAMPLE";
3.
Enter the secret key for your application. For example, it should look similar to the following:
String secretKey = "EXAMPLE<secretkey>EXAMPLE";
4.
Enter the API key for your application. For example, it should look similar to the following:
String apiKey = "EXAMPLExV2lcV2zEKTLNYs625zfk2jh4EXAMPLE";
5.
Enter a name for your application. Application names must be made up of only uppercase and
lowercase ASCII letters, numbers, underscores, hyphens, and periods, and must be between 1 and
256 characters long. For example, it should look similar to the following:
String applicationName = "baidupushapp";
6.
Run the application. You should see output similar to the following in the output window of your IDE:
===========================================
Getting Started with Amazon SNS
===========================================
{PlatformApplicationArn: arn:aws:sns:us-west-2:111122223333:app/BAIDU/TestApp}
{EndpointArn: arn:aws:sns:us-west-2:111122223333:endpoint/BAIDU/Test
App/8f3fdf0d-520b-38d1-8ed2-3301a477eef3}
{Message Body: {"BAIDU":"{\"title\":\"New Notification Received from
SNS\",\"description\":\"Hello World!\"}"}}
{Message Attributes: ("AWS.SNS.MOBILE.BAIDU.MessageKey": "default-channelmsg-key"),("AWS.SNS.MOBILE.BAIDU.DeployStatus": "1"),("AWS.SNS.MO
BILE.BAIDU.MessageType": "0")}
Published!
{MessageId=56a3a3e6-4b4b-59b4-8d1d-eff592c0ffa1}
On your Android device, you should see a push notification message appear within the Android app,
similar to the following:
Note the following considerations when using the Amazon SNS API to create an endpoint for use with
Baidu:
In CreateEndpointRequest, the platform token field should contain the channelId.
If you specify the endpoint attribute "Token" in the attributes map, this field must encapsulate the
channelId as well.
The channelId should also be specified as an endpoint attribute with the name "ChannelId".
The value of the "ChannelId" endpoint attribute and the platform token field and/or "Token" endpoint
attribute must be identical to construct a successful request.
The userId should be specified as an endpoint attribute with the name "UserId".
For a successful response, the request must contain valid UserId and ChannelId values in the attributes.
Also, the ChannelId parameter entered using setPlatformToken(String), which is a part of
CreatePlatformEndpointRequest, must be the same as the ChannelId specified in the attributes map.
Note
The push notification message cannot exceed 256 bytes, which is the maximum size allowed
by Baidu.
Map<String, MessageAttributeValue> messageAttributes = new HashMap<String,
MessageAttributeValue>();
// Insert your desired value of Deploy Status here. 1 = DEV, 2 = PROD
messageAttributes.put("AWS.SNS.MOBILE.BAIDU.DeployStatus", new MessageAttribute
Value().withDataType("String").withStringValue("1"));
// Insert your desired value of Message Type here. 0 = IN-APP MESSAGE, 1 = ALERT
NOTIFICATION
messageAttributes.put("AWS.SNS.MOBILE.BAIDU.MessageType", new MessageAttribute
Value().withDataType("String").withStringValue("1"));
// Insert your desired value of Message Key
messageAttributes.put("AWS.SNS.MOBILE.BAIDU.MessageKey", new MessageAttribute
Value().withDataType("String").withStringValue("test-message"));
PublishRequest publishRequest = new PublishRequest();
publishRequest.setMessageAttributes(messageAttributes);
String message = "{\"title\":\"Test_Title\",\"description\":\"Test_Descrip
tion\"}";
publishRequest.setMessage(message);
publishRequest.setTargetArn("arn:aws:sns:us-west-2:999999999999:end
point/BAIDU/TestApp/309fc7d3-bc53-3b63-ac42-e359260ac740");
PublishResult publishResult = snsClient.publish(publishRequest);
Note the following considerations when using the optional message attributes for structuring the message:
AWS.SNS.MOBILE.BAIDU.DeployStatus
Possible Values (Default = 1):
1 Tags the notification as being sent in a development environment
2 Tags the notification as being sent in a production environment
AWS.SNS.MOBILE.BAIDU.MessageType
Possible Values (Default = 1):
0 Generates an in-app message
1 Generates an alert notification. Alert notifications are restricted to the following format:
{"title":"<TITLE>","description":"<DESCRIPTION>"}
<TITLE> and <DESCRIPTION> are the title and description you desire for your alert notification. If the
message is incorrectly formatted JSON, the request fails.
AWS.SNS.MOBILE.BAIDU.MessageKey
A short message identifier you can attach to your message
Step 4: Send a Push Notification Message to a Mobile Endpoint using GCM (p. 70)
GCM Prerequisites
To send push notification messages to an Android app, you need the following:
Android app registered with GCM
Registration ID
Server API key (sender auth token)
If you already have these prerequisites, then you can either use the Amazon SNS console to send a push
notification message to the mobile endpoint or you can use the Amazon SNS API. For more information
about using the Amazon SNS console, see Using Amazon SNS Mobile Push (p. 78). For more information
about using the Amazon SNS API, see Step 4: Send a Push Notification Message to a Mobile Endpoint
using GCM (p. 70).
If you do not already have a Google API project, then see the Creating a Google API project in the
Android developer documentation.
Note
If you do not already have an Android app registered with GCM, then you can use the sample
Android app provided by AWS as a template to get started. For more information, see Step
3: Obtain a Registration ID from GCM (p. 69).
2.
3.
On the Google APIs Console web site, verify that you have an Google API project.
Click Services, and make sure Google Cloud Messaging for Android is turned on.
On the Google APIs Console web site, click API Access and make note of the server API key with
the Key for server apps (with IP locking) label.
If you have not yet created a server API key, then click Create new Server key. This key will be
used later in this section to send a push notification to a mobile endpoint.
Note
The provided sample Android app is compatible with physical devices running Android version
2.3 or later and with virtual devices running Google API 17 or later.
3.
Add the Project Number for your Google API project to the strings.xml file. In your IDE, you will
find the file included in the values folder, which is a subfolder of res. The string will look similar to
the following:
<string name="project_number">012345678912</string>
4.
5.
Run the app to see the registration ID as output to the Android logging system. If you are using
Eclipse with the Android ADT plug-in, you can see the registration ID in the LogCat display window.
For example, the output containing the registration ID will look similar to the following:
You should now have a registration ID, server API key, and Android app registered with GCM. You can
now send a notification to the Android app on your device by either using the Amazon SNS console or
the Amazon SNS API. To use the Amazon SNS console, see Using Amazon SNS Mobile Push (p. 78).
To use the Amazon SNS API, see Step 4: Send a Push Notification Message to a Mobile Endpoint using
GCM (p. 70).
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
2.
Import the SNSSamples folder to the top-level directory of the newly created Java project. In Eclipse,
right-click the name of the Java project and then click Import, expand General, click File System,
click Next, browse to the SNSSamples folder, click OK, and then click Finish.
3.
Right-click the Java project folder, click Build Path, and then click Configure Build Path...
2.
3.
2.
Locate the demoAndroidAppNotification method and enter the registration ID you received
from GCM for the value of the registration ID string. For example, it should look similar to the following:
String registrationId = = "EXAMPLE-kLMchcX0v3xOxWVhG6TfdBp...KT2TGkvnKyTvLuS
pzK_qsHgxVB_UpmcUa7Gl6g3EXAMPLE";
3.
Enter the API key for your application. For example, it should look similar to the following:
String serverAPIKey = "EXAMPLExV2lcV2zEKTLNYs625zfk2jh4EXAMPLE";
4.
Enter a name for your application. Application names must be made up of only uppercase and
lowercase ASCII letters, numbers, underscores, hyphens, and periods, and must be between 1 and
256 characters long. For example, it should look similar to the following:
String applicationName = "gcmpushapp";
5.
Run the application. You should see output similar to the following in the output window of your IDE:
===========================================
Getting Started with Amazon SNS
===========================================
{PlatformApplicationArn: arn:aws:sns:us-west-2:111122223333:app/GCM/gcmpush
app}
{EndpointArn: arn:aws:sns:us-west-2:111122223333:endpoint/GCM/gcmpush
app/5e3e9847-3183-3f18-a7e8-671c3a57d4b3}
{"default":"This is the default mes
sage","GCM":"{\"delay_while_idle\":true,\"collapse_key\":\"Wel
come\",\"data\":{\"message\":\"Visit Amazon!\",\"url\":\"ht
tp://www.amazon.com/\"},\"time_to_live\":125,\"dry_run\":false}"}
Published. MessageId=1ca8d7d1-c261-5bfc-8689-9db269c4e46c
On your Android device, you should see a push notification message appear within the Android app,
similar to the following:
MPNS Prerequisites
To send an unauthenticated push notification message to a Windows Phone app using Amazon SNS
and MPNS, you need the following:
Windows Phone app configured to use MPNS
Push notification URI from MPNS
To send an authenticated push notification message to a Windows Phone app using Amazon SNS and
MPNS, you also need the following:
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
3.
Right-click the Java project folder, click Build Path, and then click Configure Build Path...
Click the Libraries tab, and then click Add Library....
Click AWS SDK for Java, click Next, and then click Finish.
2.
3.
Locate the demoMPNSAppNotification method and enter the notification URI you received from
MPNS for the value of the notificationChannelURI string.
Enter a name for your application. Application names must be made up of only uppercase and
lowercase ASCII letters, numbers, underscores, hyphens, and periods, and must be between 1 and
256 characters long. For example, it should look similar to the following:
String applicationName = "mpnspushapp";
4.
Enter the MPNS TLS certificate in .pem file format. You must include the complete certificate chain,
beginning with the root CA certificate at the top and ending with the issued certificate at the bottom.
At the beginning of each new line in your certificate, you must add \n. For example, it should look
similar to the following:
5.
Enter the private key for the MPNS TLS certificate in .pem file format. At the beginning of each new
line in your certificate, you must add \n. For example, it should look similar to the following:
String privateKey = "-----BEGIN RSA PR1VATE KEY-----\nMJICiTCHAfIC
CQD9m7oRw0uXOjANBgkqhkiG7w0BAQUFADCBiDELMAkGA1UEBhMC\nWVMxCzAJBgNVBAgTAldB
MRAwDgYDVQQHEwdTZWF0dGx2MQ8wDQYDVQQKEwZBbWF6\nVVMxCzAJBgNVBAgTAldBMRAwDgY
DVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6\n4MXNchZOFFreg4Rr3Xzhb9Rhv
lIRgsr3wU4/FYai3z96EXAMPLE=\n-----END RSA PR1VATE KEY-----";
6.
Run the application. You should see output similar to the following in the output window of your IDE:
===========================================
Getting Started with Amazon SNS
===========================================
{PlatformApplicationArn: arn:aws:sns:us-west-2:111122223333:app/MPNS/TestApp}
{EndpointArn: arn:aws:sns:us-west-2:111122223333:endpoint/MPNS/Test
App/557597f8-be4a-3035-8c6d-bb7fa8b20fef}
{Message Body: {"MPNS":"<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Noti
fication xmlns:wp=\"WPNotifica
tion\"><wp:Tile><wp:Count>23</wp:Count><wp:Title>This is a tile notifica
tion</wp:Title></wp:Tile></wp:Notification>"}}
{Message Attributes: ("AWS.SNS.MOBILE.MPNS.Type": "token"),("AWS.SNS.MO
BILE.MPNS.NotificationClass": "realtime")}
Published!
{MessageId=ce9855bf-395f-5a1a-a4b9-19ace305780d}
On your Windows Phone, you should see a push notification message appear within the app.
Topics
WNS Prerequisites (p. 76)
Step 1: Set Up Your App to Receive Push Notifications Messages (p. 76)
Step 2: Get a Push Notification URI from WNS (p. 76)
Step 3: Get a Package Security Identifier from WNS (p. 76)
Step 4: Get a Secret Key from WNS (p. 76)
Step 5: Send a Push Notification Message to an App using Amazon SNS and WNS (p. 77)
WNS Prerequisites
To send push notification messages to Windows devices using Amazon SNS and WNS, you need the
following:
Windows 8 (and later) or Windows Phone 8.1 app configured to use WNS
Push notification URI from WNS
Package security identifier
Secret key
If you already have these prerequisites, then you can send a push notification message to an app using
either the Amazon SNS console or the Amazon SNS API. For more information about using the Amazon
SNS console, see Using Amazon SNS Mobile Push (p. 78). For more information about using the Amazon
SNS API, see Step 5: Send a Push Notification Message to an App using Amazon SNS and WNS (p. 77).
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
3.
Right-click the Java project folder, click Build Path, and then click Configure Build Path...
Click the Libraries tab, and then click Add Library....
Click AWS SDK for Java, click Next, and then click Finish.
2.
3.
Locate the demoWNSAppNotification method and enter the string values for the push notification
URI, package security identifier, and secret key.
Enter a name for your application. Application names must be made up of only uppercase and
lowercase ASCII letters, numbers, underscores, hyphens, and periods, and must be between 1 and
256 characters long. For example, it should look similar to the following:
4.
Run the application. You should see output similar to the following in the output window of your IDE:
===========================================
Getting Started with Amazon SNS
===========================================
{PlatformApplicationArn: arn:aws:sns:us-west-2:111122223333:app/WNS/TestApp}
{EndpointArn: arn:aws:sns:us-west-2:111122223333:endpoint/WNS/Test
App/17cc2f2a-dfa8-3450-90c6-e1f88d820f3d}
{Message Body: {"WNS":"<badge version=\"1\" value=\"23\"/>"}}
{Message Attributes: ("AWS.SNS.MOBILE.WNS.Type": "wns/badge"),("AWS.SNS.MO
BILE.WNS.CachePolicy": "cache")}
Published!
{MessageId=d4899281-927e-5f68-9fd0-de9248be6d47}
On your Windows device, you should see a push notification message appear within the app.
3.
App names must be made up of only uppercase and lowercase ASCII letters, numbers, underscores,
hyphens, and periods, and must be between 1 and 256 characters long.
In the Push notification platform box, select the platform that the app is registered with and then
enter the appropriate credentials.
Note
If you are using one of the APNS platforms, then you can select Choose file to upload the
.p12 file (exported from Keychain Access) to Amazon SNS.
For detailed instructions on how to acquire the following information, see Getting Started with Amazon
Device Messaging (p. 39), Getting Started with Apple Push Notification Service (p. 44), Getting
Started with Baidu Cloud Push (p. 50), Getting Started with Google Cloud Messaging for
Android (p. 67), Getting Started with MPNS (p. 72), or Getting Started with WNS (p. 75).
Platform
Credentials
ADM
Client ID Go to the Amazon Mobile App Distribution Portal, click Apps and Services, click the
name of your Kindle Fire app, and then click
Security Profile.
Client Secret Go to the Amazon Mobile App
Distribution Portal, click Apps and Services,
click the name of your Kindle Fire app, and then
click Security Profile.
APNS
Certificate Select the password encrypted certificate and private key, as exported from Keychain Access on your Mac computer in the .p12
file format.
Certificate Password Enter the password.
APNS_SANDBOX
APNS_VOIP
APNS_VOIP_SANDBOX
MACOS
MACOS_SANDBOX
Platform
Credentials
Baidu
GCM
MPNS
WNS
Client Secret Enter the client secret, as described in How to authenticate with the Windows
Push Notification Service (WNS).
Package Security Identifier (SID) Enter the SID,
as described in How to authenticate with the
Windows Push Notification Service (WNS).
4.
After you have entered this information, then click Add New App.
This registers the app with Amazon SNS, which creates a platform application object for the selected
platform and then returns a corresponding PlatformApplicationArn.
Go to https://console.aws.amazon.com/sns/, click Apps, click your app, and then click Add Endpoints.
2.
In the Endpoint Token box, enter either the token ID or registration ID, depending on which notification
service. For example, with ADM and GCM you enter the registration ID.
(Optional) In the User Data box, enter arbitrary information to associate with the endpoint. Amazon
SNS does not use this data. The data must be in UTF-8 format and less than 2KB.
Finally, click Add Endpoints.
3.
4.
Now with the endpoint created, you can either send messages directly to a mobile device or send
messages to mobile devices that are subscribed to a topic.
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWx
wRkxMaDNST2luZz01,"User data with spaces requires quotes"
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWx
wRkxMaDNST2luZz04,"Data,with,commas,requires,quotes"
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWx
wRkxMaDNST2luZz02,"Quoted data requires ""escaped"" quotes"
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWx
wRkxMaDNST2luZz03,"{""key"": ""json is allowed"", ""value"":""endpoint"",
""number"": 1}"
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWxwRkxMaDNST2luZz05,Sim
pleDataNoQuotes
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWxwRkxMaDNST2luZz06,"The
following line has no user data"
amzn1.adm-registration.v1.XpvSSUk0Rc3hTVVV--TOKEN--KMTlmMWxwRkxMaDNST2luZz07
APBTKzPGlCyT6E6oOfpdwLpcRNxQp5vCPFiFeru9oZylc22HvZSwQTDgmmw9WdNlXMerUPxm
pX0w1,"Different token style"
1.
Go to https://console.aws.amazon.com/sns/, click Apps, click your app, and then click Add Endpoints.
2.
Click Migrate existing tokens over to AWS, click Choose File, select your CSV file, and then click
Add Endpoints.
Note
The following steps use the Eclipse Java IDE. The steps assume you have installed the AWS
SDK for Java and you have the AWS security credentials for your AWS account. For more
information, see AWS SDK for Java. For more information about credentials, see How Do I Get
Security Credentials? in the AWS General Reference.
1.
2.
3.
Import the SNSSamples folder to the top-level directory of the newly created Java Project. In Eclipse,
right-click the name of the Java Project and then click Import, expand General, click File System,
click Next, browse to the SNSSamples folder, click OK, and then click Finish.
4.
Download a copy of the OpenCSV library and add it to the Build Path of the bulkupload package.
5.
6.
applicationarn:arn:aws:sns:us-west-2:111122223333:app/GCM/gcmpushapp
csvfilename:C:\\mytokendirectory\\mytokens.csv
goodfilename:C:\\mylogfiles\\goodtokens.csv
badfilename:C:\\mylogfiles\\badtokens.csv
delimiterchar:'
quotechar:"
numofthreads:5
7.
To register tokens from devices that will install your apps in the future
You can use one of the following two options:
Use the Amazon Cognito service: Your mobile app will need credentials to create endpoints associated
with your Amazon SNS platform application. We recommend that you use temporary credentials that
expire after a period of time. For most scenarios, we recommend that you use Amazon Cognito to
create temporary security credentials. For more information, see Creating Temporary Security Credentials
for Mobile Apps Using Identity Providers. If you would like to be notified when an app registers with
Amazon SNS, you can register to receive an Amazon SNS event that will provide the new endpoint
ARN. You can also use the ListEndpointByPlatformApplication API to obtain the full list of
endpoints registered with Amazon SNS.
Use a proxy server: If your application infrastructure is already set up for your mobile apps to call in
and register on each installation, you can continue to use this setup. Your server will act as a proxy
and pass the device token to Amazon SNS mobile push notifications, along with any user data you
would like to store. For this purpose, the proxy server will connect to Amazon SNS using your AWS
credentials and use the CreatePlatformEndpoint API call to upload the token information. The
newly created endpoint Amazon Resource Name (ARN) will be returned, which your server can store
for making subsequent publish calls to Amazon SNS.
is uninstalled and reinstalled on the same device and the endpoint for it already exists but is disabled. A
successful registration process should accomplish the following:
1. Ensure a platform endpoint exists for this app-device combination.
2. Ensure the device token in the platform endpoint is the latest valid device token.
3. Ensure the platform endpoint is enabled and ready to use.
Pseudo Code
The following pseudo code describes a recommended practice for creating a working, current, enabled
platform endpoint in a wide variety of starting conditions. This approach works whether this is a first time
the app is being registered or not, whether the platform endpoint for this app already exists, and whether
the platform endpoint is enabled, has the correct device token, and so on. It is safe to call it multiple times
in a row, as it will not create duplicate platform endpoints or change an existing platform endpoint if it is
already up to date and enabled.
retrieve the latest device token from the mobile operating system
if (the platform endpoint ARN is not stored)
# this is a first-time registration
call create platform endpoint
store the returned platform endpoint ARN
endif
call get endpoint attributes on the platform endpoint ARN
if (while getting the attributes a not-found exception is thrown)
# the platform endpoint was deleted
call create platform endpoint with the latest device token
store the returned platform endpoint ARN
else
if (the device token in the endpoint does not match the latest one) or
(get endpoint attributes shows the endpoint as disabled)
call set endpoint attributes to set the latest device token and then enable
the platform endpoint
endif
endif
This approach can be used any time the app wants to register or re-register itself. It can also be used
when notifying Amazon SNS of a device token change. In this case, you can just call the action with the
latest device token value. Some points to note about this approach are:
There are two cases where it may call the create platform endpoint action. It may be called at the very
beginning, where the app does not know its own platform endpoint ARN, as happens during a first-time
registration. It is also called if the initial get endpoint attributes action call fails with a not-found exception,
as would happen if the application knows its endpoint ARN but it was deleted.
The get endpoint attributes action is called to verify the platform endpoint's state even if the platform
endpoint was just created. This happens when the platform endpoint already exists but is disabled. In
this case, the create platform endpoint action succeeds but does not enable the platform endpoint, so
you must double-check the state of the platform endpoint before returning success.
Java Example
Here is an implementation of the previous pseudo code in Java:
class RegistrationExample {
AmazonSNSClient client = new AmazonSNSClient(); //provide credentials here
private void registerWithSNS() {
String endpointArn = retrieveEndpointArn();
String token = "Retrieved from the mobile operating system";
boolean updateNeeded = false;
boolean createNeeded = (null == endpointArn);
if (createNeeded) {
// No platform endpoint ARN is stored; need to call createEndpoint.
endpointArn = createEndpoint();
createNeeded = false;
}
System.out.println("Retrieving platform endpoint data...");
// Look up the platform endpoint and make sure the data in it is current,
even if
// it was just created.
try {
GetEndpointAttributesRequest geaReq =
new GetEndpointAttributesRequest()
.withEndpointArn(endpointArn);
GetEndpointAttributesResult geaRes =
client.getEndpointAttributes(geaReq);
updateNeeded = !geaRes.getAttributes().get("Token").equals(token)
|| !geaRes.getAttributes().get("Enabled").equalsIgnoreCase("true");
} catch (NotFoundException nfe) {
// We had a stored ARN, but the platform endpoint associated with it
// disappeared. Recreate it.
createNeeded = true;
}
if (createNeeded) {
createEndpoint();
}
System.out.println("updateNeeded = " + updateNeeded
if (updateNeeded) {
// The platform endpoint is out of sync with the current data;
// update the token and enable it.
System.out.println("Updating platform endpoint " + endpointArn);
Map attribs = new HashMap();
attribs.put("Token", token);
attribs.put("Enabled", "true");
SetEndpointAttributesRequest saeReq =
new SetEndpointAttributesRequest()
.withEndpointArn(endpointArn)
.withAttributes(attribs);
client.setEndpointAttributes(saeReq);
}
}
/**
* @return never null
* */
private String createEndpoint() {
String endpointArn = null;
try {
System.out.println("Creating platform endpoint with token " + token);
CreatePlatformEndpointRequest cpeReq =
new CreatePlatformEndpointRequest()
.withPlatformApplicationArn(applicationArn)
.withToken(token);
CreatePlatformEndpointResult cpeRes = client
.createPlatformEndpoint(cpeReq);
endpointArn = cpeRes.getEndpointArn();
} catch (InvalidParameterException ipe) {
String message = ipe.getErrorMessage();
System.out.println("Exception message: " + message);
Pattern p = Pattern
.compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " +
"with the same token.*");
Matcher m = p.matcher(message);
if (m.matches()) {
// The platform endpoint already exists for this token, but with
// additional custom data that
// createEndpoint doesn't want to overwrite. Just use the
// existing platform endpoint.
endpointArn = m.group(1);
} else {
// Rethrow the exception, the input is actually bad.
throw ipe;
}
}
storeEndpointArn(endpointArn);
return endpointArn;
}
/**
* @return the ARN the app was registered under previously, or null if no
*
platform endpoint ARN is stored.
*/
private String retrieveEndpointArn() {
// Retrieve the platform endpoint ARN from permanent storage,
// or return null if null is stored.
return arnStorage;
}
/**
* Stores the platform endpoint ARN in permanent storage for lookup next time.
* */
private void storeEndpointArn(String endpointArn) {
// Write the platform endpoint ARN to permanent storage.
arnStorage = endpointArn;
}
}
Troubleshooting
Repeatedly Calling Create Platform Endpoint with an Outdated Device Token
Especially for GCM endpoints, you may think it is best to store the first device token the application is
issued and then call the create platform endpoint with that device token every time on application startup.
This may seem correct since it frees the app from having to manage the state of the device token and
Amazon SNS will automatically update the device token to its latest value. However, this solution has a
number of serious issues:
Amazon SNS relies on feedback from GCM to update expired device tokens to new device tokens.
GCM retains information on old device tokens for some time, but not indefinitely. Once GCM forgets
about the connection between the old device token and the new device token, Amazon SNS will no
longer be able to update the device token stored in the platform endpoint to its correct value; it will just
disable the platform endpoint instead.
The platform application will contain multiple platform endpoints corresponding to the same device
token.
Amazon SNS imposes a limit to the number of platform endpoints that can be created starting with the
same device token. Eventually, the creation of new endpoints will fail with an invalid parameter exception
and the following error message: "This endpoint is already registered with a different token."
Go to https://console.aws.amazon.com/sns/.
In the left Navigation pane, click Apps and click the app that you want to send a message to.
On the Application Details screen, select Endpoint Actions and then click Publish.
4.
On the Publish dialog box, enter the message to appear in the app on the mobile device and then
click Publish.
The notification message will then be sent from Amazon SNS to the platform notification service,
which will then send the message to the app.
2.
Follow the steps as described in Subscribe to a Topic (p. 5). You just need to select Application
in the Protocol drop-down menu and then enter the mobile endpoint Amazon Resource Name (ARN)
in the Endpoint box.
Follow the steps to publish messages to a topic, as described in Publish to a Topic (p. 6), then all
mobile endpoints that are subscribed to the topic will be sent the message.
{
"GCM":"{
"data":{
"message":"Check out these awesome deals!",
"url":"www.amazon.com"
}
}"
}
When sending messages using the console quotation marks must be escaped (\"), as the following
example shows.
{
"GCM":"{
\"data\":{
\"message\":\"Check out these awesome deals!\",
\"url\":\"www.amazon.com\"
}
}"
}
When entered in the Amazon SNS console, the example should look similar to the following:
{
"GCM":"{\"data\":{\"message\":\"Check out these awesome
deals!\",\"url\":\"www.amazon.com\"}}"
}
{
"GCM":"{
"data":{
"message":"Check out these awesome deals!",
"url":"www.amazon.com"
},
"time_to_live": 3600,
"collapse_key": "deals"
}"
}
When entered in the Amazon SNS console, the example should look similar to the following:
{
"GCM":"{\"data\":{\"message\":\"Check out these awesome
deals!\",\"url\":\"www.amazon.com\"},\"time_to_live\": 3600,\"col
lapse_key\":\"deals\"}"
}
For a list of the supported key-value pairs in each of the push notification services supported in Amazon
SNS, see the following links:
APNS Apple Push Notification Service
GCM Implementing GCM Server Message Parameters
ADM Sending a Message
{
"default": "This is the default message which must be present when publishing
a message to a topic. The default message will only be used if a message is not
present for
one of the notification platforms.",
"APNS": "{\"aps\":{\"alert\": \"Check out these awesome
deals!\",\"url\":\"www.amazon.com\"} }",
"GCM":"{\"data\":{\"message\":\"Check out these awesome
deals!\",\"url\":\"www.amazon.com\"}}",
"ADM": "{ \"data\": { \"message\": \"Check out these awesome
deals!\",\"url\":\"www.amazon.com\" }}"
}
Determine the message dwell time (the time between the publish timestamp and just before handing
off to a push notification service).
To configure application attributes for message delivery status, you can use the AWS Management
Console, AWS software development kits (SDKs), or query API.
Topics
Configuring Message Delivery Status Attributes with the AWS Management Console (p. 91)
Amazon SNS Message Delivery Status CloudWatch Log Examples (p. 91)
Configuring Message Delivery Status Attributes with the AWS SDKs (p. 92)
Platform Response Codes (p. 93)
5.
6.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left Navigation pane, click Apps, and then click the app containing the endpoints for which
you want receive CloudWatch Logs.
Click Application Actions and then click Delivery Status.
On the Delivery Status dialog box, click Create IAM Roles.
You will then be redirected to the IAM console.
Click Allow to give Amazon SNS write access to use CloudWatch Logs on your behalf.
Now, back on the Delivery Status dialog box, enter a number in the Percentage of Success to
Sample (0-100) field for the percentage of successful messages sent for which you want to receive
CloudWatch Logs.
Note
After you configure application attributes for message delivery status, all failed message
deliveries generate CloudWatch Logs.
7.
Finally, click Save Configuration. You will now be able to view and parse the CloudWatch Logs
containing the message delivery status. For more information about using CloudWatch, see the
CloudWatch Documentation.
FAILURE
{
"status": "FAILURE",
"notification": {
"timestamp": "2015-01-26 23:29:35.678",
"messageId": "c3ad79b0-8996-550a-8bfa-24f05989898f"
},
"delivery": {
"statusCode": 8,
"dwellTimeMs": 1451,
"token": "ex
amp1e29z6j5c4df46f809505189c4c83fjcgf7f6257e98542d2jt3395kj73",
"attempts": 1,
"providerResponse": "NotificationErrorResponse(command=8, status=Inval
idToken, id=1, cause=null)",
"destination": "arn:aws:sns:us-east-1:111122223333:endpoint/APNS_SAND
BOX/APNSPushApp/986cb8a1-4f6b-34b1-9a1b-d9e9cb553944"
}
}
For a list of push notification service response codes, see the section called Platform Response
Codes (p. 93).
SetPlatformApplicationAttributesRequest setPlatformApplicationAttributesRequest
= new SetPlatformApplicationAttributesRequest();
Map<String, String> attributes = new HashMap<>();
attributes.put("SuccessFeedbackRoleArn",
"arn:aws:iam::111122223333:role/SNS_CWlogs");
attributes.put("FailureFeedbackRoleArn",
"arn:aws:iam::111122223333:role/SNS_CWlogs");
attributes.put("SuccessFeedbackSampleRate", "5");
setPlatformApplicationAttributesRequest.withAttributes(attributes);
setPlatformApplicationAttributesRequest.setPlatformApplication
Arn("arn:aws:sns:us-west-2:111122223333:app/GCM/GCMPushApp");
sns.setPlatformApplicationAttributes(setPlatformApplicationAttributesRequest);
For more information about the SDK for Java, see Getting Started with the AWS SDK for Java.
Response Codes
Attribute name
Description
EventEndpointCreated
EventEndpointDeleted
EventEndpointUpdated
EventDeliveryFailure
Note
To track delivery failures on the platform application side, subscribe
to message delivery status events for the application. For more
information, see Using Amazon SNS Application Attributes for
Message Delivery Status.
Each of the preceding attributes can be associated with an application. The application can then receive
these event notifications.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the service navigation pane, choose Applications.
Choose the name of the application that you want to set event notifications for.
Choose Actions, Configure events.
For each of the events that you want to send events notifications for, type the corresponding Amazon
SNS topic ARN.
Choose Save configuration. The event notifications are set.
AWS CLI
Run the set-platform-application-attributes command.
The following example sets the same Amazon SNS topic for all four application events:
aws sns set-platform-application-attributes
--platform-application-arn arn:aws:sns:us-east-1:12345EXAMPLE:app/GCM/MyGCMPlat
formApplication
--attributes EventEndpointCreated="arn:aws:sns:us-east-1:12345EXAMPLE:MyGCMPlat
formApplicationEvents",
EventEndpointDeleted="arn:aws:sns:us-east-1:12345EXAMPLE:MyGCMPlatformApplica
tionEvents",
EventEndpointUpdated="arn:aws:sns:us-east-1:12345EXAMPLE:MyGCMPlatformApplica
tionEvents",
EventDeliveryFailure="arn:aws:sns:us-east-1:12345EXAMPLE:MyGCMPlatformApplica
tionEvents"
AWS SDKs
Call one of the following APIs, depending on your target programming language or platform:
Programming language
or platform
Android
setPlatformApplicationAttributes
iOS
AWSSNSSetPlatformApplicationAttributesInput
Java
setPlatformApplicationAttributes
JavaScript
setPlatformApplicationAttributes
.NET
SetPlatformApplicationAttributes
PHP
SetPlatformApplicationAttributes
Python (boto)
set_platform_application_attributes
Ruby
set_platform_application_attributes
Unity
SetPlatformApplicationAttributesAsync
Windows PowerShell
Set-SNSPlatformApplicationAttributes
AWS.SNS.MOBILE.ADM.TTL
AWS.SNS.MOBILE.APNS.TTL
AWS.SNS.MOBILE.APNS_SANDBOX.TTL
AWS.SNS.MOBILE.BAIDU.TTL
AWS.SNS.MOBILE.GCM.TTL
AWS.SNS.MOBILE.WNS.TTL
Each of the push notification services handle TTL differently. Amazon SNS provides an abstract view of
TTL over all the push notification services, which makes it easier to specify TTL. When you use the AWS
Management Console to specify TTL (in seconds), you only have to enter the TTL value once and Amazon
SNS will then calculate the TTL for each of the selected push notification services when publishing the
message.
TTL is relative to the publish time. Before handing off a push notification message to a specific push
notification service, Amazon SNS computes the dwell time (the time between the publish timestamp and
just before handing off to a push notification service) for the push notification and passes the remaining
TTL to the specific push notification service. If TTL is shorter than the dwell time, Amazon SNS won't
attempt to publish.
If you specify a TTL for a push notification message, then the TTL value must be a positive integer, unless
the value of 0 has a specific meaning for the push notification servicesuch as with APNS and GCM. If
the TTL value is set to 0 and the push notification service does not have a specific meaning for 0, then
Amazon SNS will drop the message. For more information about the TTL parameter set to 0 when using
APNS, see expiration date. For more information about the TTL parameter set to 0 when using GCM,
see Lifetime of a message.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left Navigation pane, click Apps, and then click the app containing the endpoints you want
to set TTL for when publishing a message.
Select the endpoints to publish a message to, click Endpoint Actions and then click Publish.
On the Publish dialog box, enter the number of seconds for Time to Live (TTL) and then click Publish
Message.
For more information about using message attributes with Amazon SNS, see Using Amazon SNS Message
Attributes (p. 164).
a notification message to a mobile app and device, or you could use the EndpointArn attribute with the
Subscribe action for subscription to a topic. For more information, see Amazon SNS Mobile Push
HighLevel Steps (p. 38).
The following is a list and description of the Amazon SNS mobile push APIs:
API
Description
CreatePlatformApplication
SetPlatformApplicationAttributes
GetPlatformApplicationAttributes
ListPlatformApplications
Lists the platform application objects for the supported push notification services. For more information,
see ListPlatformApplications in the Amazon Simple
Notification Service API Reference.
DeletePlatformApplication
Deletes a platform application object. For more information, see DeletePlatformApplication in the
Amazon Simple Notification Service API Reference.
CreatePlatformEndpoint
SetEndpointAttributes
GetEndpointAttributes
API
Description
ListEndpointsByPlatformApplication
DeleteEndpoint
Description
CreatePlatformApplication
400
CreatePlatformApplication
Platform Name is invalid An invalid or out-ofrange value was supplied for the platform
name.
400
CreatePlatformApplication
CreatePlatformApplication
APNS Principal is a
valid cert but not in a
.pem format
CreatePlatformApplication
CreatePlatformApplication
Error
Description
CreatePlatformApplication
CreatePlatformApplication
APNS Credential is
not provided
CreatePlatformApplication
CreatePlatformApplication
GCM serverAPIKey
is not provided
CreatePlatformApplication
GCM serverAPIKey
is empty
400
CreatePlatformApplication
GCM serverAPIKey
is a null string
400
CreatePlatformApplication
GCM serverAPIKey
is invalid
400
CreatePlatformApplication
ADM clientsecret is
not provided
400
CreatePlatformApplication
400
CreatePlatformApplication
ADM client_secret is
empty string
400
CreatePlatformApplication
Error
Description
ADM client_secret is
not valid
400
CreatePlatformApplication
ADM client_id is
empty string
400
CreatePlatformApplication
400
CreatePlatformApplication
400
CreatePlatformApplication
CreatePlatformApplication
EventEndpointCreated
has invalid ARN format
EventEndpointCreated 400
has invalid ARN format.
CreatePlatformApplication
EventEndpointDeleted
has invalid ARN format
EventEndpointDeleted 400
has invalid ARN format.
CreatePlatformApplication
EventEndpointUpdated
has invalid ARN format
EventEndpointUpdated 400
has invalid ARN format.
CreatePlatformApplication
400
CreatePlatformApplication
EventDeliveryFailure
has invalid ARN format
EventDeliveryFailure
400
has invalid ARN format.
CreatePlatformApplication
EventEndpointCreated
is not an existing Topic
EventEndpointCreated
is not an existing topic.
400
CreatePlatformApplication
EventEndpointDeleted
is not an existing Topic
EventEndpointDeleted
is not an existing topic.
400
CreatePlatformApplication
EventEndpointUpdated
is not an existing Topic
EventEndpointUpdated
is not an existing topic.
400
CreatePlatformApplication
CreatePlatformApplication
EventDeliveryFailure is
not an existing Topic
EventDeliveryFailure is
not an existing topic.
CreatePlatformApplication
SetPlatformAttributes
SetPlatformAttributes
400
400
Error
Description
SetPlatformAttributes
APNS Principal is a
valid cert but not in a
.pem format
SetPlatformAttributes
SetPlatformAttributes
SetPlatformAttributes
SetPlatformAttributes
APNS Credential is
not provided
SetPlatformAttributes
SetPlatformAttributes
GCM serverAPIKey
is not provided
SetPlatformAttributes
Error
Description
GCM serverAPIKey
is a null string
400
SetPlatformAttributes
400
SetPlatformAttributes
400
SetPlatformAttributes
ADM clientsecret is
not provided
400
SetPlatformAttributes
400
SetPlatformAttributes
EventEndpointUpdated
has invalid ARN format
EventEndpointUpdated 400
has invalid ARN format.
SetPlatformAttributes
EventEndpointDeleted
has invalid ARN format
EventEndpointDeleted 400
has invalid ARN format.
SetPlatformAttributes
EventEndpointUpdated
has invalid ARN format
EventEndpointUpdated 400
has invalid ARN format.
SetPlatformAttributes
400
SetPlatformAttributes
EventDeliveryFailure
has invalid ARN format
EventDeliveryFailure
400
has invalid ARN format.
SetPlatformAttributes
EventEndpointCreated
is not an existing Topic
EventEndpointCreated
is not an existing topic.
400
SetPlatformAttributes
EventEndpointDeleted
is not an existing Topic
EventEndpointDeleted
is not an existing topic.
400
SetPlatformAttributes
EventEndpointUpdated
is not an existing Topic
EventEndpointUpdated
is not an existing topic.
400
SetPlatformAttributes
SetPlatformAttributes
EventDeliveryFailure is
not an existing Topic
EventDeliveryFailure is
not an existing topic.
400
SetPlatformAttributes
400
GetPlatformApplicationAttributes
403
GetPlatformApplicationAttributes
400
ListPlatformApplications
Error
Description
400
ListEndpointsByPlatformApplication
404
ListEndpointsByPlatformApplication
400
ListEndpointsByPlatformApplication
400
DeletePlatformApplication
403
DeletePlatformApplication
400
CreatePlatformEndpoint
404
CreatePlatformEndpoint
400
CreatePlatformEndpoint
CreatePlatformEndpoint
CreatePlatformEndpoint
DeleteEndpoint
DeleteEndpoint
SetEndpointAttributes
403
SetEndpointAttributes
400
SetEndpointAttributes
SetEndpointAttributes
403
Error
Description
SetEndpointAttributes
GetEndpointAttributes
GetEndpointAttributes
Publish
Publish
403
400
Publish
Publish
Note
Instead of following the steps listed below, you can now subscribe an Amazon SQS queue to
an Amazon SNS topic using the Amazon SQS console, which simplifies the process. For more
information, see Subscribe Queue to Amazon SNS Topic
To enable an Amazon SNS topic to send messages to an Amazon SQS queue, follow these steps:
1. Get the Amazon Resource Name (ARN) of the queue you want to send messages to and the topic to
which you want to subscribe the queue. (p. 107)
2. Give sqs:SendMessage permission to the Amazon SNS topic so that it can send messages to the
queue. (p. 108)
3. Subscribe the queue to the Amazon SNS topic. (p. 109)
4. Give IAM users or AWS accounts the appropriate permissions to publish to the Amazon SNS topic
and read messages from the Amazon SQS queue. (p. 109)
5. Test it out by publishing a message to the topic and reading the message from the queue. (p. 111)
To learn about how to set up a topic to send messages to a queue that is in a different AWS account,
see Sending Amazon SNS messages to an Amazon SQS queue in a different account (p. 112).
To see an AWS CloudFormation template that creates a topic that sends messages to two queues, see
Using an AWS CloudFormation Template to Create a Topic that Sends Messages to Amazon SQS
Queues (p. 115).
Sign in to the AWS Management Console and open the Amazon SQS console at https://
console.aws.amazon.com/sqs/.
Select the box for the queue whose ARN you want to get.
From the Details tab, copy the ARN value so that you can use it to subscribe to the Amazon SNS
topic.
To get the topic ARN, you can use the Amazon SNS console, the sns-get-topic-attributes command, or
the GetQueueAttributes API action.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the navigation pane, select the topic whose ARN you want to get.
From the Topic Details pane, copy the Topic ARN value so that you can use it to give permission
for the Amazon SNS topic to send messages to the queue.
5.
Sign in to the AWS Management Console and open the Amazon SQS console at https://
console.aws.amazon.com/sqs/.
Select the box for the queue whose policy you want to set, click the Permissions tab, and then click
Add a Permission.
In the Add a Permission dialog box, select Allow for Effect, select Everybody (*) for Principal,
and then select SendMessage from the Actions drop-down.
Add a condition that allows the action for the topic. Click Add Conditions (optional), select ArnEquals
for Condition, select aws:SourceArn for Key, and paste in the topic ARN for Value. Click Add
Condition. The new condition should appear at the bottom of the box (you may have to scroll down
to see this).
Click Add Permission.
If you wanted to create the policy document yourself, you would create a policy like the following. The
policy allows MyTopic to send messages to MyQueue.
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"MySQSPolicy001",
"Effect":"Allow",
"Principal":"*",
"Action":"sqs:SendMessage",
"Resource":"arn:aws:sqs:us-east-1:123456789012:MyQueue",
"Condition":{
"ArnEquals":{
"aws:SourceArn":"arn:aws:sns:us-east-1:123456789012:MyTopic"
}
}
}
]
}
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the navigation pane, select the topic.
3.
Click Create Subscription, select Amazon SQS for Protocol, paste in the ARN for the queue that
you want the topic to send messages to for Endpoint, and click Subscribe.
4.
If you added the following policy to an IAM user or group, you would give that user or members of that
group permission to perform the sqs:ReceiveMessage and sqs:DeleteMessage actions on the queues
MyQueue1 and MyQueue2.
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"AllowReadDeleteMessageOnMyQueue",
"Effect":"Allow",
"Action":[
"sqs:ReceiveMessage",
"sqs:DeleteMessage"
],
"Resource":[
"arn:aws:sns:us-east-1:123456789012:MyQueue1",
"arn:aws:sns:us-east-1:123456789012:MyQueue2"
],
}
]
}
Note
When you give another AWS account access to a resource in your account, you are also giving
IAM users who have admin-level access (wildcard access) permissions to that resource. All
other IAM users in the other account are automatically denied access to your resource. If you
want to give specific IAM users in that AWS account access to your resource, the account or an
IAM user with admin-level access must delegate permissions for the resource to those IAM
users. For more information about cross-account delegation, see Enabling Cross-Account Access
in the Using IAM Guide.
If you added the following policy to a topic MyTopic in account 123456789012, you would give account
111122223333 permission to perform the sns:Publish action on that topic.
{
"Version":"2012-10-17",
"Id":"MyTopicPolicy",
"Statement":[{
"Sid":"Allow-publish-to-topic",
"Effect":"Allow",
"Principal":{
"AWS":"111122223333"
},
"Action":"sns:Publish",
"Resource":"arn:aws:sns:us-east-1:123456789012:MyTopic"
}
]
}
If you added the following policy to a queue MyQueue in account 123456789012, you would give account
111122223333 permission to perform the sqs:ReceiveMessage and sqs:DeleteMessage actions on
that queue.
{
"Version":"2012-10-17",
"Id":"MyQueuePolicy",
"Statement":[
{
"Sid":"Allow-Processing-Of-Messages-for-Queue",
"Effect":"Allow",
"Principal":{
"AWS":"111122223333"
},
"Action":[
"sqs:DeleteMessage",
"sqs:ReceiveMessage"
],
"Resource":[
"arn:aws:sns:us-east-1:123456789012:MyQueue",
]
}
]
}
Step 5. Test it
You can test a topic's queue subscriptions by publishing to the topic and viewing the message that the
topic sends to the queue.
Using the credentials of the AWS account or IAM user with permission to publish to the topic, sign
in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
3.
In the navigation pane, select the topic and click Publish to Topic.
In the Subject box, enter a subject (for example, Testing publish to queue) in the Message
box, enter some text (for example, Hello world!), and click Publish Message. The following
message appears: Your message has been successfully published.
To view the message from the topic using the Amazon SQS console
1.
Using the credentials of the AWS account or IAM user with permission to view messages in the
queue, sign in to the AWS Management Console and open the Amazon SQS console at https://
console.aws.amazon.com/sqs/.
2.
3.
Check the box for the queue that is subscribed to the topic.
From the Queue Action drop-down, select View/Delete Messages and click Start Polling for
Messages. A message with a type of Notification appears.
In the Body column, click More Details. The Message Details box contains a JSON document that
contains the subject and message that you published to the topic. The message looks similar to the
following JSON document.
4.
{
"Type" : "Notification",
"MessageId" : "63a3f6b6-d533-4a47-aef9-fcf5cf758c76",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Subject" : "Testing publish to subscribed queues",
"Message" : "Hello world!",
"Timestamp" : "2012-03-29T05:12:16.901Z",
"SignatureVersion" : "1",
"Signature" : "EXAMPLEnTrFPa37tnVO0FF9Iau3MGzjlJLRfySEoWz4uZHSj6ycK4ph71Zm
dv0NtJ4dC/El9FOGp3VuvchpaTraNHWhhq/OsN1HVz20zxmF9b88R8GtqjfKB5woZZmz87HiM6CY
DTo3l7LMwFT4VU7ELtyaBBafhPTg9O5CnKkg=",
"SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotification
Service-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
"UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsub
scribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:c7fe3a54ab0e-4ec2-88e0-db410a0f2bee"
}
5.
Click Close.You have successfully published to a topic that sends notification messages to a queue.
account 123456789012, the following policy gives the account 111122223333 permission to call
sns:Subscribe on MyTopic in the account 123456789012.
{
"Version":"2012-10-17",
"Id":"MyTopicSubscribePolicy",
"Statement":[{
"Sid":"Allow-other-account-to-subscribe-to-topic",
"Effect":"Allow",
"Principal":{
"AWS":"111122223333"
},
"Action":"sns:Subscribe",
"Resource":"arn:aws:sns:us-east-1:123456789012:MyTopic"
}
]
}
After this policy has been set on MyTopic, a user can log in to the Amazon SNS console with credentials
for account 111122223333 to subscribe to the topic.
To add an Amazon SQS queue subscription to a topic in another account using the Amazon
SQS console
1.
Using the credentials of the AWS account containing the queue or an IAM user in that account, sign
in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2. Make sure you have the ARNs for both the topic and the queue. You will need them when you create
the subscription.
3. Make sure you have set sqs:SendMessage permission on the queue so that it can receive messages
from the topic. For more information, see Step 2. Give permission to the Amazon SNS topic to send
messages to the Amazon SQS queue (p. 108).
4. In the navigation pane, select the SNS Dashboard.
5. In the Dashboard, in the Additional Actions section, click Create New Subscription.
6. In the Topic ARN box, enter the ARN for the topic.
7. For Protocol, select Amazon SQS.
8. In the Endpoint box, enter the ARN for the queue.
9. Click Subscribe.
10. For the Subscription request received! message, you'll notice text that says you must confirm the
subscription. Because you are the queue owner, the subscription does not need to be confirmed.
Click Close. You've completed the subscription process and notification messages published to the
topic can now be sent to the queue.
The user can also use the access key and secret key for the AWS account 111122223333 to issue the
sns-subscribe command or call the Subscribe API action to subscribe an Amazon SQS queue to
MyTopic in the account 123456789012. The following sns-subscribe command subscribes the queue
MyQ from account 111122223333 to the topic MyTopic in account 123456789012.
sns-subscribe arn:aws:sns:us-east-1:123456789012:MyTopic --protocol sqs --end
point arn:aws:sqs:us-east-1:111122223333:MyQ
Important
Before you subscribe to the topic, make sure you have set sqs:SendMessage permission on
the queue so that it can receive messages from the topic. See Step 2. Give permission to the
Amazon SNS topic to send messages to the Amazon SQS queue (p. 108).
When the user calls the Subscribe action, a message of type SubscriptionConfirmation is sent
to the queue and the subscription is displayed in the Amazon SNS console with its Subscription ID set
to Pending Confirmation. To confirm the subscription, a user who can read messages from the queue
must visit the URL specified in the SubscribeURL value in the message. Until the subscription is confirmed,
no notifications published to the topic are sent to the queue. To confirm a subscription, you can use the
Amazon SQS console or the ReceiveMessage API action.
5.
Sign in to the AWS Management Console and open the Amazon SQS console at https://
console.aws.amazon.com/sqs/.
Select the queue that has a pending subscription to the topic.
From the Queue Action drop-down, select View/Delete Messages and click Start Polling for
Messages. A message with a type of SubscriptionConfirmation appears.
In the Body column, click More Details.
In the text box, find the SubscribeURL value and copy the URL. It will look similar to the following
URL.
https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&Topi
cArn=arn:aws:sns:us-west-2:123456789012:MyTop
ic&Token=2336412f37fb687f5d51e6e241d09c805d352fe148e56f8cff30f023ff35db8bccbc62721725b074841be6524bb215b0c45ec571ba1e7faacc309940c0b4b9e511ab85eba671412a4c314ecd446127ff1a9cfe08642b8e3738e73c279dd3ae565bd98f842ed992a4742ebec0946ebd9a
6.
In a web browser, paste the URL into the address bar to visit the URL.You will see a response similar
to the following XML document.
<ConfirmSubscriptionResponse xmlns="http://sns.amazonaws.com/doc/2010-0331/">
<ConfirmSubscriptionResult>
<SubscriptionArn>arn:aws:sns:us-west-2:123456789012:MyTopic:c7fe3a54ab0e-4ec2-88e0-db410a0f2bee</SubscriptionArn>
</ConfirmSubscriptionResult>
<ResponseMetadata>
<RequestId>dd266ecc-7955-11e1-b925-5140d02da9af</RequestId>
</ResponseMetadata>
</ConfirmSubscriptionResponse>
If you view the topic subscription in the Amazon SNS console, you will now see that subscription
ARN replaces the Pending Confirmation message in the Subscription ID column. The subscribed
queue is ready to receive messages from the topic.
"Resources":{
"MySNSTopic":{
"Type":"AWS::SNS::Topic",
"Properties":{
"Subscription":[
{
"Endpoint":{"Fn::GetAtt":["MyQueue1","Arn"]},
"Protocol":"sqs"
},
{
"Endpoint":{"Fn::GetAtt":["MyQueue2","Arn"]},
"Protocol":"sqs"
}
]
}
},
"MyQueue1":{
"Type":"AWS::SQS::Queue"
},
"MyQueue2":{
"Type":"AWS::SQS::Queue"
},
"MyPublishUser":{
"Type":"AWS::IAM::User",
"Properties":{
"LoginProfile":{
"Password":{"Ref":"MyPublishUserPassword"}
}
}
},
"MyPublishUserKey":{
"Type":"AWS::IAM::AccessKey",
"Properties":{
"UserName":{"Ref":"MyPublishUser"}
}
},
"MyPublishTopicGroup":{
"Type":"AWS::IAM::Group",
"Properties":{
"Policies":[
{
"PolicyName":"MyTopicGroupPolicy",
"PolicyDocument":{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"sns:Publish"
],
"Resource":{"Ref":"MySNSTopic"}
Note
Display names are not case sensitive, and Amazon SNS converts display names to uppercase
characters for SMS messages.
You can use SMS notifications in conjunction with other notification types, such as email. For example,
if you use CloudWatch to monitor your AWS application, you can create a CloudWatch alarm that is
associated with an Amazon SNS topic. You can then subscribe to the topic via both email and SMS so
that you receive notifications not only through email, but also on your SMS-enabled device.
To facilitate the use of a single message for both SMS and email notifications, Amazon SNS checks
whether your message contains both a message body and a subject. If you publish a message that
contains only a message body, both SMS and email subscribers receive the same message, up to the
size limits for each protocol (140 characters for SMS and 256 KB for email). If your message is longer
than 140 characters, your SMS message will be truncated.
To avoid a truncated SMS message when your message payload is longer than 140 characters, publish
a message with both a subject and a message payload. For messages with both a subject and a message
payload, Amazon SNS sends only the subject to SMS subscribers, but sends both the subject and the
message to any email subscribers. This allows you to send email notifications up to 256 KB long and
also have the subject line delivered as an SMS message to your mobile device.
Note
SMS notifications are currently supported for phone numbers in the United States. SMS messages
can be sent only from topics created in the US East (N. Virginia) region. However, you can
publish messages to topics that you create in the US East (N. Virginia) region from any other
region.
Amazon SNS uses short code 30304 to send and receive SMS messages.
Prerequisites
Sign up for Amazon SNSCreate an AWS account if you don't have one.
For more information, see Before You Begin (p. 4).
Create an Amazon SNS topicCreate an Amazon SNS topic if you don't have one.
For more information, see Create a Topic (p. 5).
After you have completed both of the prerequisite tasks, you can use the following process to publish
and receive SMS messages with Amazon SNS.
Process for Sending and Receiving SMS Messages with Amazon SNS
Task 1: Assign a Topic Display Name (p. 122)
Task 2: Subscribe to a Topic Using the SMS Protocol (p. 123)
Task 3: Publish a Message (p. 124)
Task 4: Cancel SMS Subscriptions (p. 125)
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select a topic.
3.
Click the Other actions drop-down list and then select Edit topic display name.
4.
In the Display Name box, type a display name and click Set display name.
The new topic display name appears in the Topic Details page.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select the topic.
Click the Other actions drop-down list and then select Subscribe to topic.
In the Protocol drop-down list, select SMS.
In the Endpoint box, type the phone number of an SMS-enabled device and then click Create
subscription.
Note
Use numbers only. Do not include dashes, spaces, or parentheses.
Amazon SNS sends a confirmation text message to the SMS-enabled device associated with the
number you entered.
6.
In the Amazon SNS console, the subscription is listed as PendingConfirmation until the SMS-enabled
device confirms the subscription.
Use the SMS-enabled device associated with the phone number you entered in the previous step
to reply affirmatively to the confirmation text message. For example, the following text message
confirms a subscription to the MyTopic Amazon SNS topic.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select the topic you want to publish to.
Click the Publish to topic button.
In the Subject box, type a subject if you want to use the Message box for messages to email
subscribers.
5.
If you include text in the Subject box, the SMS message will contain the subject text rather than the
text from the Message box. Any email subscribers, however, will receive both the subject and the
message body. This allows you to use a single published message to send a short SMS message
using the subject and a longer email message using the message payload.
In the Message box, type a message.
6.
Amazon SNS sends text that you enter in the Message box to SMS subscribers unless you also
enter text into the Subject box.
Click Publish message.
Amazon SNS displays a confirmation dialog box.
The SMS message appears on your SMS-enabled device.
Use your SMS-enabled device to send a STOP or QUIT message to short code 30304. For example,
the following text message cancels both of the subscriptions that this device had with Amazon SNS.
Use your SMS-enabled device to send an SMS message that contains STOP <TOPICNAME> to short
code 30304, where <TOPICNAME> is the display name of the topic. For example, the following SMS
message cancels a subscription to a topic named mytopic.
To enable an Amazon SNS topic to send messages to an HTTP or HTTPS endpoint, follow these steps:
Step 1: Make sure your endpoint is ready to process Amazon SNS messages (p. 128)
Step 2: Subscribe the HTTP/HTTPS endpoint to the Amazon SNS topic (p. 131)
Step 3: Confirm the subscription (p. 132)
Step 4: Set the delivery retry policy for the subscription (optional) (p. 132)
Step 5: Give users permissions to publish to the topic (optional) (p. 132)
Step 6: Send messages to the HTTP/HTTPS endpoint (p. 133)
Your code should read the HTTP headers of the HTTP POST requests that Amazon SNS sends to
your endpoint. Your code should look for the header field x-amz-sns-message-type, which tells
you the type of message that Amazon SNS has sent to you. By looking at the header, you can
determine the message type without having to parse the body of the HTTP request. There are two
types that you need to handle: SubscriptionConfirmation and Notification. The
UnsubscribeConfirmation message is used only when the subscription is deleted from the topic.
API Version 2010-03-31
128
For details about the HTTP header, see HTTP/HTTPS Headers (p. 175). The following HTTP POST
request is an example of a subscription confirmation message.
POST / HTTP/1.1
x-amz-sns-message-type: SubscriptionConfirmation
x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
Content-Length: 1336
Content-Type: text/plain; charset=UTF-8
Host: example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
{
"Type" : "SubscriptionConfirmation",
"MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
"Token" :
"2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582af
bacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Message" : "You have chosen to subscribe to the topic arn:aws:sns:uswest-2:123456789012:MyTopic.\nTo confirm the subscription, visit the Sub
scribeURL included in this message.",
"SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSub
scription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTop
ic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582af
bacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
"Timestamp" : "2012-04-26T20:45:04.751Z",
"SignatureVersion" : "1",
"Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNK
WLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvol
IC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
"SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotification
Service-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
}
2.
3.
Your code should parse the JSON document in the body of the HTTP POST request to read the
name/value pairs that make up the Amazon SNS message. Use a JSON parser that handles converting
the escaped representation of control characters back to their ASCII character values (for example,
converting \n to a newline character). You can use an existing JSON parser such as the Jackson
JSON Processor (http://wiki.fasterxml.com/JacksonHome) or write your own. In order to send the
text in the subject and message fields as valid JSON, Amazon SNS must convert some control
characters to escaped representations that can be included in the JSON document. When you receive
the JSON document in the body of the POST request sent to your endpoint, you must convert the
escaped characters back to their original character values if you want an exact representation of the
original subject and messages published to the topic. This is critical if you want to verify the signature
of a notification because the signature uses the message and subject in their original forms as part
of the string to sign.
Your code should verify the authenticity of a notification, subscription confirmation, or unsubscribe
confirmation message sent by Amazon SNS. Using information contained in the Amazon SNS
message, your endpoint can recreate the signature so that you can verify the contents of the message
by matching your signature with the signature that Amazon SNS sent with the message. For more
information about verifying the signature of a message, see Verifying the Signatures of Amazon SNS
Messages (p. 153).
4.
Based on the type specified by the header field x-amz-sns-message-type, your code should read
the JSON document contained in the body of the HTTP request and process the message. Here are
the guidelines for handling the two primary types of messages:
SubscriptionConfirmation
Read the value for SubscribeURL and visit that URL. To confirm the subscription and start
receiving notifications at the endpoint, you must visit the SubscribeURLURL (for example, by
sending an HTTP GET request to the URL). See the example HTTP request in the previous step
to see what the SubscribeURL looks like. For more information about the format of the
SubscriptionConfirmation message, see HTTP/HTTPS Subscription Confirmation JSON
Format (p. 176). When you visit the URL, you will get back a response that looks like the following
XML document. The document returns the subscription ARN for the endpoint within the
ConfirmSubscriptionResult element.
<ConfirmSubscriptionResponse xmlns="http://sns.amazonaws.com/doc/201003-31/">
<ConfirmSubscriptionResult>
<SubscriptionArn>arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf3905c3-41de-beaa-fcfcc21c8f55</SubscriptionArn>
</ConfirmSubscriptionResult>
<ResponseMetadata>
<RequestId>075ecce8-8dac-11e1-bf80-f781d96e9307</RequestId>
</ResponseMetadata>
</ConfirmSubscriptionResponse>
As an alternative to visiting the SubscribeURL, you can confirm the subscription using the
ConfirmSubscription action with the Token set to its corresponding value in the
SubscriptionConfirmation message. If you want to allow only the topic owner and
subscription owner to be able to unsubscribe the endpoint, you call the ConfirmSubscription
action with an AWS signature.
Notification
Read the values for Subject and Message to get the notification information that was published
to the topic.
For details about the format of the Notification message, see HTTP/HTTPS Headers (p. 175).
The following HTTP POST request is an example of a notification message sent to the endpoint
example.com.
POST / HTTP/1.1
x-amz-sns-message-type: Notification
x-amz-sns-message-id: 22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTop
ic:c9135db0-26c4-47ec-8998-413945fb5a96
Content-Length: 773
Content-Type: text/plain; charset=UTF-8
Host: example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
{
"Type" : "Notification",
"MessageId" : "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Subject" : "My First Message",
"Message" : "Hello world!",
5.
6.
7.
8.
Make sure that your endpoint responds to the HTTP POST message from Amazon SNS with the
appropriate status code. The connection will time out in 15 seconds. If your endpoint does not respond
before the connection times out or if your endpoint returns a status code outside the range of 2004xx,
Amazon SNS will consider the delivery of the message as a failed attempt.
Make sure that your code can handle message delivery retries from Amazon SNS. If Amazon SNS
doesn't receive a successful response from your endpoint, it attempts to deliver the message again.
This applies to all messages, including the subscription confirmation message. By default, if the initial
delivery of the message fails, Amazon SNS attempts up to three retries with a delay between failed
attempts set at 20 seconds. Note that the message request times out at 15 seconds. This means
that if the message delivery failure was caused by a timeout, Amazon SNS will retry approximately
35 seconds after the previous delivery attempt. If you don't like the default delivery policy, you can
set a different delivery policy on the endpoint.
To be clear, Amazon SNS attempts to retry only after a delivery attempt has failed. You can identify
a message using the x-amz-sns-message-id header field. By comparing the IDs of the messages
you have processed with incoming messages, you can determine whether the message is a retry
attempt.
If you are subscribing an HTTPS endpoint, make sure that your endpoint has a server certificate
from a trusted Certificate Authority (CA). Amazon SNS will only send messages to HTTPS endpoints
that have a server certificate signed by a CA trusted by Amazon SNS. For a list of trusted CAs, see
Certificate Authorities (CA) Recognized by Amazon SNS for HTTPS Endpoints (p. 140).
Deploy the code that you have created to receive Amazon SNS messages. When you subscribe the
endpoint, the endpoint must be ready to receive at least the subscription confirmation message.
To subscribe an HTTP or HTTPS endpoint to a topic using the Amazon SNS console
1.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
3.
In the left navigation pane, click Topics and then select the topic.
Click the Other actions drop-down list and select Subscribe to topic.
4.
5.
6.
You should use the first method for most cases (apply policies to groups and manage permissions for
users by adding or removing the appropriate users to the groups). If you need to give permissions to a
user in another account, use the second method.
If you added the following policy to an IAM user or group, you would give that user or members of that
group permission to perform the sns:Publish action on the topic MyTopic.
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"AllowPublishToMyTopic",
"Effect":"Allow",
"Action":"sns:Publish",
"Resource":"arn:aws:sns:us-east-1:123456789012:MyTopic"
}
]
}
The following example policy shows how to give another account permissions to a topic.
Note
When you give another AWS account access to a resource in your account, you are also giving
IAM users who have admin-level access (wildcard access) permissions to that resource. All
other IAM users in the other account are automatically denied access to your resource. If you
want to give specific IAM users in that AWS account access to your resource, the account or an
IAM user with admin-level access must delegate permissions for the resource to those IAM
users. For more information about cross-account delegation, see Enabling Cross-Account Access
in the Using IAM Guide.
If you added the following policy to a topic MyTopic in account 123456789012, you would give account
111122223333 permission to perform the sns:Publish action on that topic.
{
"Version":"2012-10-17",
"Id":"MyTopicPolicy",
"Statement":[{
"Sid":"Allow-publish-to-topic",
"Effect":"Allow",
"Principal":{
"AWS":"111122223333"
},
"Action":"sns:Publish",
"Resource":"arn:aws:sns:us-east-1:123456789012:MyTopic"
}
]
}
If you followed Step 1 (p. 128), the code that you deployed at your endpoint should process the notification.
Using the credentials of the AWS account or IAM user with permission to publish to the topic, sign
in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
3.
4.
In the left navigation pane, click Topics and then select a topic.
Click the Publish to topic button.
In the Subject box, enter a subject (for example, Testing publish to my endpoint).
5.
In the Message box, enter some text (for example, Hello world!), and click Publish message.
The following message appears: Your message has been successfully published.
1. Immediate Retry Phase (p. 137)Also called the no delay phase, this phase occurs immediately after
the initial delivery attempt. The value you set for Retries with no delay determines the number of
retries immediately after the initial delivery attempt. There is no delay between retries in this phase.
2. Pre-Backoff Phase (p. 138)The pre-backoff phase follows the immediate retry phase. Use this phase
to create a set of retries that occur before a backoff function applies to the retries. Use the Minimum
delay retries setting to specify the number of retries in the Pre-Backoff Phase. You can control the
time delay between retries in this phase by using the Minimum delay setting.
3. Backoff Phase (p. 138)This phase is called the backoff phase because you can control the delay
between retries in this phase using the retry backoff function. Set the Minimum delay and the Maximum
delay, and then select a Retry backoff function to define how quickly the delay increases from the
minimum delay to the maximum delay.
4. Post-Backoff Phase (p. 139)The post-backoff phase follows the backoff phase. Use the Maximum
delay retries setting to specify the number of retries in the post-backoff phase. You can control the
time delay between retries in this phase by using the Maximum delay setting.
The backoff phase is the most commonly used phase. If no delivery policies are set, the default is to retry
three times in the backoff phase, with a time delay of 20 seconds between each retry. The default value
for both the Minimum delay and the Maximum delay is 20. The default number of retries is 3, so the
default retry policy calls for a total of 3 retries with a 20 second delay between each retry. The following
diagram shows the delay associated with each retry.
To see how the retry backoff function affects the time delay between retries, you can set the maximum
delay to 40 seconds and leave the remaining settings at their default values. With this change, your
delivery policy now specifies 3 retries during the backoff phase, a minimum delay of 20 seconds, and a
maximum delay of 40 seconds. Because the default backoff function is linear, the delay between messages
increases at a constant rate over the course of the backoff phase. Amazon SNS attempts the first retry
after 20 seconds, the second retry after 30 seconds, and the final retry after 40 seconds. The following
diagram shows the delay associated with each retry.
The maximum lifetime of a message in the system is one hour. This one hour limit cannot be extended
by a delivery policy.
Note
Only HTTP and HTTPS subscription types are supported by delivery policies. Support for other
Amazon SNS subscription types (e.g., email, Amazon SQS, and SMS) is not currently available.
You can also apply delivery policies to individual subscriptions. If you assign a delivery policy to a
subscription, the subscription-level policy takes precedence over the topic-level delivery policy. In the
following diagram, one subscription has a subscription-level delivery policy whereas the two other
subscriptions do not.
In some cases, you might want to ignore all subscription delivery policies so that your topic's delivery
policy applies to all subscriptions even if a subscription has set its own delivery policy. To configure
Amazon SNS to apply your topic delivery policy to all subscriptions, click Ignore subscription override
in the View/Edit Topic Delivery Policies dialog box. The following diagram shows a topic-level delivery
policy that applies to all subscriptions, even the subscription that has its own subscription delivery policy
because subscription-level policies have been specifically ignored.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select the topic.
3.
4.
Click the Other actions drop-down list and select Edit topic delivery policy.
In the Maximum receive rate box, type an integer value (e.g., 2).
5.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
3.
4.
In the left navigation pane, click Topics and then select a topic ARN.
In the Topic Details pane, select a subscription and click Edit topic delivery policy.
In the Maximum receive rate box, type an integer value (e.g., 2).
5.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
3.
4.
In the left navigation pane, click Topics and then select a topic ARN.
In the Topic Details pane, select Edit topic delivery policy from the Other topic actions drop-down
list.
In the Retries with no delay box, type an integer value.
5.
Pre-Backoff Phase
The pre-backoff phase follows the immediate retry phase. Use this phase if you want to create a set of
one or more retries that happen before the backoff function affects the delay between retries. In this
phase, the time between retries is constant and is equal to the setting that you choose for the Minimum
delay. The Minumum delay setting affects retries in two phasesit applies to all retries in the pre-backoff
phase and serves as the initial time delay for retries in the backoff phase. The default number of retries
for this phase is 0.
4.
5.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select a topic ARN.
In the Topic Details pane, select Edit topic delivery policy from the Other topic actions drop-down
list.
In the Minimum delay retries box, type an integer value.
In the Minimum delay box, type an integer value to set the delay between messages in this phase.
6.
The value you set must be less than or equal to the value you set for Maximum delay.
Click Update policy to save your changes.
2.
3.
Backoff Phase
The backoff phase is the only phase that applies by default. You can control the number of retries in the
backoff phase using Number of retries.
Important
The value you choose for Number of retries represents the total number of retries, including
the retries you set for Retries with no delay, Minimum delay retries, and Maximum delay
retries.
You can control the frequency of the retries in the backoff phase with three parameters.
Minimum delayThe minimum delay defines the delay associated with the first retry attempt in the
backoff phase.
Maximum delayThe maximum delay defines the delay associated with the final retry attempt in the
backoff phase.
Retry backoff functionThe retry backoff function defines the algorithm that Amazon SNS uses to
calculate the delays associated with all of the retry attempts between the first and last retries in the
backoff phase.
Post-Backoff Phase
The post-backoff phase is the final phase. Use this phase if you want to create a set of one or more retries
that happen after the backoff function affects the delay between retries. In this phase, the time between
retries is constant and is equal to the setting that you choose for the Maximum delay. The Maximum
delay setting affects retries in two phasesit applies to all retries in the post-backoff phase and serves
as the final time delay for retries in the backoff phase. The default number of retries for this phase is 0.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left navigation pane, click Topics and then select a topic ARN.
4.
In the Topic Details pane, select Edit topic delivery policy from the Other topic actions drop-down
list.
In the Maximum delay retries box, type an integer value.
5.
In the Maximum delay box, type an integer value to set the delay between messages in this phase.
6.
The value you set must be greater than or equal to the value you set for Minimum delay.
Click Update policy to save your changes.
74:20:74:41:72:9C:DD:92:EC:79:31:D8:23:10:8D:C2:81:92:E2:BB
digicertglobalrootca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
A8:98:5D:3A:65:E5:E5:C4:B2:D7:D6:6D:40:C6:DD:2F:B1:9C:54:36
mozillacert66.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
DD:E1:D2:A9:01:80:2E:1D:87:5E:84:B3:80:7E:4B:B1:FD:99:41:34
mozillacert112.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
43:13:BB:96:F1:D5:86:9B:C1:4E:6A:92:F6:CF:F6:34:69:87:82:37
utnuserfirstclientauthemailca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
B1:72:B1:A5:6D:95:F9:1F:E5:02:87:E1:4D:37:EA:6A:44:63:76:8A
verisignc2g1.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
67:82:AA:E0:ED:EE:E2:1A:58:39:D3:C0:CD:14:68:0A:4F:60:14:2A
mozillacert55.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
AA:DB:BC:22:23:8F:C4:01:A1:27:BB:38:DD:F4:1D:DB:08:9E:F0:12
mozillacert101.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
99:A6:9B:E6:1A:FE:88:6B:4D:2B:82:00:7C:B8:54:FC:31:7E:15:39
mozillacert119.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
75:E0:AB:B6:13:85:12:27:1C:04:F8:5F:DD:DE:38:E4:B7:24:2E:FE
verisignc3g1.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
A1:DB:63:93:91:6F:17:E4:18:55:09:40:04:15:C7:02:40:B0:AE:6B
mozillacert44.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
5F:43:E5:B1:BF:F8:78:8C:AC:1C:C7:CA:4A:9A:C6:22:2B:CC:34:C6
mozillacert108.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
B1:BC:96:8B:D4:F4:9D:62:2A:A8:9A:81:F2:15:01:52:A4:1D:82:9C
mozillacert95.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
DA:FA:F7:FA:66:84:EC:06:8F:14:50:BD:C7:C2:81:A5:BC:A9:64:57
keynectisrootca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
9C:61:5C:4D:4D:85:10:3A:53:26:C2:4D:BA:EA:E4:A2:D2:D5:CC:97
mozillacert141.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
31:7A:2A:D0:7F:2B:33:5E:F5:A1:C3:4E:4B:57:E8:B7:D8:F1:FC:A6
equifaxsecureglobalebusinessca1, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
7E:78:4A:10:1C:82:65:CC:2D:E1:F1:6D:47:B4:40:CA:D9:0A:19:45
baltimorecodesigningca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
30:46:D8:C8:88:FF:69:30:C3:4A:FC:CD:49:27:08:7C:60:56:7B:0D
mozillacert33.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
FE:B8:C4:32:DC:F9:76:9A:CE:AE:3D:D8:90:8F:FD:28:86:65:64:7D
mozillacert0.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
97:81:79:50:D8:1C:96:70:CC:34:D8:09:CF:79:44:31:36:7E:F4:74
mozillacert84.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
D3:C0:63:F2:19:ED:07:3E:34:AD:5D:75:0B:32:76:29:FF:D5:9A:F2
85:B5:FF:67:9B:0C:79:96:1F:C8:6E:44:22:00:46:13:DB:17:92:84
mozillacert25.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
4E:B6:D5:78:49:9B:1C:CF:5F:58:1E:AD:56:BE:3D:9B:67:44:A5:E5
verisignclass1g2ca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
27:3E:E1:24:57:FD:C4:F9:0C:55:E8:2B:56:16:7F:62:F5:32:E5:47
mozillacert76.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
F9:B5:B6:32:45:5F:9C:BE:EC:57:5F:80:DC:E9:6E:2C:C7:B2:78:B7
mozillacert122.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
02:FA:F3:E2:91:43:54:68:60:78:57:69:4D:F5:E4:5B:68:85:18:68
godaddysecurecertificationauthority, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
7C:46:56:C3:06:1F:7F:4C:0D:67:B3:19:A8:55:F6:0E:BC:11:FC:44
mozillacert14.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
5F:B7:EE:06:33:E2:59:DB:AD:0C:4C:9A:E6:D3:8F:1A:61:C7:DC:25
equifaxsecureca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
D2:32:09:AD:23:D3:14:23:21:74:E4:0D:7F:9D:62:13:97:86:63:3A
mozillacert65.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
69:BD:8C:F4:9C:D3:00:FB:59:2E:17:93:CA:55:6A:F3:EC:AA:35:FB
mozillacert111.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
9C:BB:48:53:F6:A4:F6:D3:52:A4:E8:32:52:55:60:13:F5:AD:AF:65
certumtrustednetworkca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
07:E0:32:E0:20:B7:2C:3F:19:2F:06:28:A2:59:3A:19:A7:0F:06:9E
mozillacert129.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
E6:21:F3:35:43:79:05:9A:4B:68:30:9D:8A:2F:74:22:15:87:EC:79
mozillacert54.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
03:9E:ED:B8:0B:E7:A0:3C:69:53:89:3B:20:D2:D9:32:3A:4C:2A:FD
mozillacert100.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
58:E8:AB:B0:36:15:33:FB:80:F7:9B:1B:6D:29:D3:FF:8D:5F:00:F0
mozillacert118.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
7E:78:4A:10:1C:82:65:CC:2D:E1:F1:6D:47:B4:40:CA:D9:0A:19:45
mozillacert151.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
AC:ED:5F:65:53:FD:25:CE:01:5F:1F:7A:48:3B:6A:74:9F:61:78:C6
thawteprimaryrootcag3, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
F1:8B:53:8D:1B:E9:03:B6:A6:F0:56:43:5B:17:15:89:CA:F3:6B:F2
quovadisrootca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
DE:3F:40:BD:50:93:D3:9B:6C:60:F6:DA:BC:07:62:01:00:89:76:C9
thawteprimaryrootcag2, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
AA:DB:BC:22:23:8F:C4:01:A1:27:BB:38:DD:F4:1D:DB:08:9E:F0:12
deprecateditsecca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
12:12:0B:03:0E:15:14:54:F4:DD:B3:F5:DE:13:6E:83:5A:29:72:9D
85:37:1C:A6:E5:50:14:3D:CE:28:03:47:1B:DE:3A:09:E8:F8:77:0F
mozillacert143.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
36:B1:2B:49:F9:81:9E:D7:4C:9E:BC:38:0F:C6:56:8F:5D:AC:B2:F7
mozillacert35.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
2A:C8:D5:8B:57:CE:BF:2F:49:AF:F2:FC:76:8F:51:14:62:90:7A:41
mozillacert2.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
22:D5:D8:DF:8F:02:31:D1:8D:F7:9D:B7:CF:8A:2D:64:C9:3F:6C:3A
utnuserfirstobjectca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
E1:2D:FB:4B:41:D7:D9:C3:2B:30:51:4B:AC:1D:81:D8:38:5E:2D:46
mozillacert86.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
74:2C:31:92:E6:07:E4:24:EB:45:49:54:2B:E1:BB:C5:3E:61:74:E2
mozillacert132.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
39:21:C1:15:C1:5D:0E:CA:5C:CB:5B:C4:F0:7D:21:D8:05:0B:56:6A
addtrustclass1ca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
CC:AB:0E:A0:4C:23:01:D6:69:7B:DD:37:9F:CD:12:EB:24:E3:94:9D
mozillacert24.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
59:AF:82:79:91:86:C7:B4:75:07:CB:CF:03:57:46:EB:04:DD:B7:16
verisignc1g3.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
20:42:85:DC:F7:EB:76:41:95:57:8E:13:6B:D4:B7:D1:E9:8E:46:A5
mozillacert9.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
F4:8B:11:BF:DE:AB:BE:94:54:20:71:E6:41:DE:6B:BE:88:2B:40:B9
amzninternalrootca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
A7:B7:F6:15:8A:FF:1E:C8:85:13:38:BC:93:EB:A2:AB:A4:09:EF:06
mozillacert75.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
D2:32:09:AD:23:D3:14:23:21:74:E4:0D:7F:9D:62:13:97:86:63:3A
entrustevca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
B3:1E:B1:B7:40:E3:6C:84:02:DA:DC:37:D4:4D:F5:D4:67:49:52:F9
secomscrootca2, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
5F:3B:8C:F2:F8:10:B3:7D:78:B4:CE:EC:19:19:C3:73:34:B9:C7:74
camerfirmachambersignca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
4A:BD:EE:EC:95:0D:35:9C:89:AE:C7:52:A1:2C:5B:29:F6:D6:AA:0C
secomscrootca1, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
36:B1:2B:49:F9:81:9E:D7:4C:9E:BC:38:0F:C6:56:8F:5D:AC:B2:F7
mozillacert121.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
CC:AB:0E:A0:4C:23:01:D6:69:7B:DD:37:9F:CD:12:EB:24:E3:94:9D
mozillacert139.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
DE:3F:40:BD:50:93:D3:9B:6C:60:F6:DA:BC:07:62:01:00:89:76:C9
mozillacert13.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
06:08:3F:59:3F:15:A1:04:A0:69:A4:6B:A9:03:D0:06:B7:97:09:91
FE:B8:C4:32:DC:F9:76:9A:CE:AE:3D:D8:90:8F:FD:28:86:65:64:7D
mozillacert67.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
D6:9B:56:11:48:F0:1C:77:C5:45:78:C1:09:26:DF:5B:85:69:76:AD
globalsignr3ca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
D6:9B:56:11:48:F0:1C:77:C5:45:78:C1:09:26:DF:5B:85:69:76:AD
mozillacert113.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
50:30:06:09:1D:97:D4:F5:AE:39:F7:CB:E7:92:7D:7D:65:2D:34:31
aolrootca2, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
85:B5:FF:67:9B:0C:79:96:1F:C8:6E:44:22:00:46:13:DB:17:92:84
trustcenteruniversalcai, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
6B:2F:34:AD:89:58:BE:62:FD:B0:6B:5C:CE:BB:9D:D9:4F:4E:39:F3
aolrootca1, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
39:21:C1:15:C1:5D:0E:CA:5C:CB:5B:C4:F0:7D:21:D8:05:0B:56:6A
mozillacert56.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
F1:8B:53:8D:1B:E9:03:B6:A6:F0:56:43:5B:17:15:89:CA:F3:6B:F2
verisignc2g2.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
B3:EA:C4:47:76:C9:C8:1C:EA:F2:9D:95:B6:CC:A0:08:1B:67:EC:9D
verisignclass1g3ca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
20:42:85:DC:F7:EB:76:41:95:57:8E:13:6B:D4:B7:D1:E9:8E:46:A5
mozillacert102.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
96:C9:1B:0B:95:B4:10:98:42:FA:D0:D8:22:79:FE:60:FA:B9:16:83
addtrustexternalca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
02:FA:F3:E2:91:43:54:68:60:78:57:69:4D:F5:E4:5B:68:85:18:68
verisignclass3ca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
A1:DB:63:93:91:6F:17:E4:18:55:09:40:04:15:C7:02:40:B0:AE:6B
verisignc3g2.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
85:37:1C:A6:E5:50:14:3D:CE:28:03:47:1B:DE:3A:09:E8:F8:77:0F
mozillacert45.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
67:65:0D:F1:7E:8E:7E:5B:82:40:A4:F4:56:4B:CF:E2:3D:69:C6:F0
verisignc4g2.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
0B:77:BE:BB:CB:7A:A2:47:05:DE:CC:0F:BD:6A:02:FC:7A:BD:9B:52
digicertassuredidrootca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
05:63:B8:63:0D:62:D7:5A:BB:C8:AB:1E:4B:DF:B5:A8:99:B2:4D:43
verisignclass1ca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
CE:6A:64:A3:09:E4:2F:BB:D9:85:1C:45:3E:64:09:EA:E8:7D:60:F1
mozillacert109.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
B5:61:EB:EA:A4:DE:E4:25:4B:69:1A:98:A5:57:47:C2:34:C7:D9:71
thawtepremiumserverca, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
E0:AB:05:94:20:72:54:93:05:60:62:02:36:70:F7:CD:2E:FC:66:66
E7:B4:F6:9D:61:EC:90:69:DB:7E:90:A7:40:1A:3C:F4:7D:4F:E8:EE
mozillacert48.pem, Apr 22, 2014, trustedCertEntry,
Certificate fingerprint (SHA1):
A0:A1:AB:90:C9:FC:84:7B:3B:12:61:E8:97:7D:5F:D3:22:61:D3:CC
Always use HTTPS when getting the certificate from Amazon SNS.
Validate the authenticity of the certificate.
Verify the certificate was received from Amazon SNS.
When possible, use one of the supported AWS SDKs for Amazon SNS to validate and verify messages.
For example, with the AWS SDK for PHP you would use the isValid method from the
MessageValidator class.
For example code for a Java servlet that handles Amazon SNS messages , see Example Code for an
Amazon SNS Endpoint Java Servlet (p. 155).
To verify the signature of an Amazon SNS message when using HTTP query-based requests
1.
2.
3.
Extract the name/value pairs from the JSON document in the body of the HTTP POST request that
Amazon SNS sent to your endpoint. You'll be using the values of some of the name/value pairs to
create the string to sign. When you are verifying the signature of an Amazon SNS message, it is
critical that you convert the escaped control characters to their original character representations in
the Message and Subject values. These values must be in their original forms when you use them
as part of the string to sign. For information about how to parse the JSON document, see Step 1:
Make sure your endpoint is ready to process Amazon SNS messages (p. 128).
The SignatureVersion tells you the signature version. From the signature version, you can
determine the requirements for how to generate the signature. For Amazon SNS notifications, Amazon
SNS currently supports signature version 1. This section provides the steps for creating a signature
using signature version 1.
Get the X509 certificate that Amazon SNS used to sign the message. The SigningCertURL value
points to the location of the X509 certificate used to create the digital signature for the message.
Retrieve the certificate from this location.
Extract the public key from the certificate. The public key from the certificate specified by
SigningCertURL is used to verify the authenticity and integrity of the message.
4.
Determine the message type. The format of the string to sign depends on the message type, which
is specified by the Type value.
5.
Create the string to sign. The string to sign is a newline characterdelimited list of specific name/value
pairs from the message. Each name/value pair is represented with the name first followed by a
newline character, followed by the value, and ending with a newline character. The name/value pairs
must be listed in byte-sort order.
Depending on the message type, the string to sign must have the following name/value pairs.
Notification
Notification messages must contain the following name/value pairs:
Message
MessageId
Subject (if included in the message)
Timestamp
TopicArn
Type
2012-06-03T19:25:13.719Z
Token
2336412f37fb687f5d51e6e241d09c8058323f60b964268bfe08ce35640228c208a66d3621bd9f7b012918cf
d
cfe65e153df551f76df58ed147f1245e330ce77ceff06dedab9f051f7028657e6c42750bf64bc9ef711d494e9f7637b86e690779eb5568f72466806b246bd244fa9392b1bc01eeb1c5e420847a745b7aa4b0085
TopicArn
arn:aws:sns:us-west-2:123456789012:s4-MySNSTopic-1G1WEFCOXTC0P
Type
SubscriptionConfirmation
6.
Decode the Signature value from Base64 format. The message delivers the signature in the
Signature value, which is encoded as Base64. Before you compare the signature value with the
signature you have calculated, make sure that you decode the Signature value from Base64 so
that you compare the values using the same format.
7.
Generate the derived hash value of the Amazon SNS message. Submit the Amazon SNS message,
in canonical format, to the same hash function used to generate the signature.
8.
Generate the asserted hash value of the Amazon SNS message. The asserted hash value is the
result of using the public key value (from step 3) to decrypt the signature delivered with the Amazon
SNS message.
Verify the authenticity and integrity of the Amazon SNS message. Compare the derived hash value
(from step 7) to the asserted hash value (from step 8). If the values are identical, then the receiver
is assured that the message has not been modified while in transit and the message must have
originated from Amazon SNS. If the values are not identical, it should not be trusted by the receiver.
9.
The following example Java method creates a signature using information from a Message object that
contains the data sent in the request body and verifies that signature against the original Base64-encoded
signature of the message, which is also read from the Message object.
private static boolean isMessageSignatureValid(Message msg) {
try {
URL url = new URL(msg.getSigningCertURL());
InputStream inStream = url.openStream();
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate)cf.generateCertificate(in
Stream);
inStream.close();
Signature sig = Signature.getInstance("SHA1withRSA");
sig.initVerify(cert.getPublicKey());
sig.update(getMessageBytesToSign(msg));
return sig.verify(Base64.decodeBase64(msg.getSignature()));
}
catch (Exception e) {
throw new SecurityException("Verify method failed.", e);
}
}
The following example Java methods work together to create the string to sign for an Amazon SNS
message. The getMessageBytesToSign method calls the appropriate string-to-sign method based on
the message type and runs the string to sign as a byte array. The buildNotificationStringToSign
and buildSubscriptionStringToSign methods create the string to sign based on the formats
described in Verifying the Signatures of Amazon SNS Messages (p. 153).
Prerequisites
To invoke Lambda functions using Amazon SNS notifications, you need the following:
Lambda function
Amazon SNS topic
For information on creating a Lambda function, see Getting Started with AWS Lambda. For information
on creating a Amazon SNS topic, see Create a Topic.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
3.
In the left Navigation pane, click Topics, and then click the topic to which you want to subscribe a
Lambda endpoint.
Click Actions and then click Subscribe to topic.
4.
5.
6.
7.
In the Endpoint drop-down box, select the ARN for the Lambda function.
In the Version or Alias drop-down box, select an available version or alias to use. You can also
choose $LATEST to specifiy the latest version of the Lambda function. If you do not want to specify
a version or alias, you can also choose default, which is functionally the same as $LATEST. For
more information, see AWS Lambda Function Versioning and Aliases.
Click Create subscription.
When a message is published to an SNS topic that has a Lambda function subscribed to it, the Lambda
function is invoked with the payload of the published message. For information on how to create a sample
message history store using SNS, Lambda, and Amazon DynamoDB, see the AWS Mobile Development
blog Invoking AWS Lambda functions via Amazon SNS.
Application
HTTP
Lambda
SQS
After you configure the message delivery status attributes, log entries will be sent to CloudWatch Logs
for messages sent to a topic subscribed to an Amazon SNS endpoint. Logging message delivery status
helps provide better operational insight, such as the following:
Knowing whether a message was delivered to the Amazon SNS endpoint.
Identifying the response sent from the Amazon SNS endpoint to Amazon SNS.
Determining the message dwell time (the time between the publish timestamp and just before handing
off to an Amazon SNS endpoint).
To configure topic attributes for message delivery status, you can use the AWS Management Console,
AWS software development kits (SDKs), or query API.
Topics
Configuring Message Delivery Status Attributes with the AWS Management Console (p. 162)
Configuring Message Delivery Status Attributes for Topics Subscribed to Amazon SNS Endpoints
with the AWS SDKs (p. 162)
To configure message delivery status for notifications from Amazon SNS to a Lambda
endpoint:
1.
2.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
In the left Navigation pane, click Topics, and then click the topic to which you want to receive
message delivery status information.
3.
4.
5.
6.
7.
Note
After you configure application attributes for message delivery status, all failed message
deliveries generate CloudWatch Logs.
8.
Topic Attributes
You can use the following topic attribute name values for message delivery status:
Application
ApplicationSuccessFeedbackRoleArn
ApplicationSuccessFeedbackSampleRate
ApplicationFailureFeedbackRoleArn
Note
In addition to being able to configure topic attributes for message delivery status of notification
messages sent to Amazon SNS application endpoints, you can also configure application
attributes for the delivery status of push notification messages sent to push notification services.
For more information, see Using Amazon SNS Application Attributes for Message Delivery
Status.
HTTP
HTTPSuccessFeedbackRoleArn
HTTPSuccessFeedbackSampleRate
HTTPFailureFeedbackRoleArn
Lambda
LambdaSuccessFeedbackRoleArn
LambdaSuccessFeedbackSampleRate
LambdaFailureFeedbackRoleArn
SQS
SQSSuccessFeedbackRoleArn
SQSSuccessFeedbackSampleRate
SQSFailureFeedbackRoleArn
The <ENDPOINT>SuccessFeedbackRoleArn and <ENDPOINT>FailureFeedbackRoleArn attributes
are used to give Amazon SNS write access to use CloudWatch Logs on your behalf. The
<ENDPOINT>SuccessFeedbackSampleRate attribute is for specifying the sample rate percentage
(0-100) of successfully delivered messages. After you configure the
<ENDPOINT>FailureFeedbackRoleArn attribute, then all failed message deliveries generate CloudWatch
Logs.
For more information about the SDK for Java, see Getting Started with the AWS SDK for Java.
Important
To use message attributes with Amazon SQS endpoints, you must set the subscription attribute,
Raw Message Delivery, to True. For more information about Raw Message Delivery, see
Appendix: Large Payload and Raw Message Delivery (p. 183)
You can also use message attributes to help structure the push notification message for mobile endpoints.
In this scenario the message attributes are only used to help structure the push notification message and
are not delivered to the endpoint, as they are when sending messages with message attributes to Amazon
SQS endpoints.
Topics
Message Attribute Items and Validation (p. 164)
Message Attribute Data Types and Validation (p. 165)
Reserved Message Attributes (p. 165)
Using Message Attributes with the AWS SDKs (p. 166)
Type The supported message attribute data types are String, Number, and Binary. The data type
has the same restrictions on the content as the message body. The data type is case sensitive, and it
can be up to 256 bytes long. For more information, see the Message Attribute Data Types and
Validation (p. 165) section.
Value 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 the Publish action
in the Amazon Simple Notification Service API Reference.
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).
Allowed Values
Baidu
AWS.SNS.MOBILE.BAIDU.DeployStatus
(optional)
1development environment.
2production environment. (default
1)
AWS.SNS.MOBILE.BAIDU.MessageType
(optional)
AWS.SNS.MOBILE.BAIDU.MessageKey
(optional)
MPNS
AWS.SNS.MOBILE.MPNS.Type (required)
AWS.SNS.MOBILE.MPNS.NotificationClass
(required)
Allowed Values
WNS
AWS.SNS.MOBILE.WNS.Type (required)
same as X-WNS-Type
For more information about using message attributes with Baidu, see Using Message Attributes for
Structuring the Message (p. 66).
Note
There is no charge for the Amazon SNS metrics reported in CloudWatch; they are provided as
part of the Amazon SNS service.
4.
Sign in to the AWS Management Console and open the CloudWatch console at https://
console.aws.amazon.com/cloudwatch/.
Click View Metrics.
From the Viewing drop-down menu select either SNS: Topic Metrics, SNS: Push Notifications
by Application, SNS: Push Notifications by Application and Platform, or SNS: Push Notifications
by Platform to show the available metrics.
Click a specific item to see more detail, such as a graph of the data collected. For example, the
following graph of the selected metric, NumberOfMessagesPublished, shows the average number
of published Amazon SNS messages for a five-minute period throughout the time range of 6 hours.
API Version 2010-03-31
167
Call mon-get-stats. You can learn more about this and other metrics-related functions in the
Amazon CloudWatch Developer Guide.
Call GetMetricStatistics. You can learn more about this and other metrics-related functions in
the Amazon CloudWatch API Reference.
Sign in to the AWS Management Console and open the CloudWatch console at https://
console.aws.amazon.com/cloudwatch/.
Click Alarms, and then click the Create Alarm button. This launches the Create Alarm wizard.
Scroll through the Amazon SNS metrics to locate the metric you want to place an alarm on. Select
the metric to create an alarm on and click Continue.
Fill in the Name, Description, Threshold, and Time values for the metric, and then click Continue.
Choose Alarm as the alarm state. If you want CloudWatch to send you an email when the alarm
state is reached, either select a preexisting Amazon SNS topic or click Create New Email Topic. If
API Version 2010-03-31
168
you click Create New Email Topic, you can set the name and email addresses for a new topic. This
list will be saved and appear in the drop-down box for future alarms. Click Continue.
Note
If you use Create New Email Topic to create a new Amazon SNS topic, the email addresses
must be verified before they will receive notifications. Emails are sent only when the alarm
enters an alarm state. If this alarm state change happens before the email addresses are
verified, they will not receive a notification.
6.
At this point, the Create Alarm wizard gives you a chance to review the alarm youre about to create.
If you need to make any changes, you can use the Edit links on the right. Once you are satisfied,
click Create Alarm.
For more information about using CloudWatch and alarms, see the CloudWatch Documentation.
Description
NumberOfMessagesPublished
PublishSize
Units: Bytes
Valid Statistics: Minimum, Maximum, Average and Count
NumberOfNotificationsDelivered
NumberOfNotificationsFailed
Description
Application
Application,Platform
Platform
TopicName
CreateTopic
DeleteEndpoint
DeletePlatformApplication
DeleteTopic
GetEndpointAttributes
GetPlatformApplicationAttributes
GetSubscriptionAttributes
GetTopicAttributes
API Version 2010-03-31
171
ListEndpointsByPlatformApplication
ListPlatformApplications
ListSubscriptions
ListSubscriptionsByTopic
ListTopics
RemovePermission
SetEndpointAttributes
SetPlatformApplicationAttributes
SetSubscriptionAttributes
SetTopicAttributes
Subscribe
Unsubscribe
Note
When you are not logged in to Amazon Web Services (unauthenticated mode) and either the
ConfirmSubscription or Unsubscribe actions are invoked, then they will not be logged to CloudTrail.
Such as, when you click the provided link in an email notification to confirm a pending subscription
to a topic, the ConfirmSubscription action is invoked in unauthenticated mode. In this
example, the ConfirmSubscription action would not be logged to CloudTrail.
Every log entry contains information about who generated the request. The user identity information in
the log helps you determine whether the request was made with root or IAM user credentials, with
temporary security credentials for a role or federated user, or by another AWS service. For more
information, see the userIdentity field in the CloudTrail Event Reference.
You can store your log files in your bucket for as long as you want, but you can also define Amazon S3
lifecycle rules to archive or delete log files automatically. By default, your log files are encrypted by using
Amazon S3 server-side encryption (SSE).
You can choose to have CloudTrail publish Amazon SNS notifications when new log files are delivered
if you want to take quick action upon log file delivery. For more information, see Configuring Amazon
SNS Notifications.
You can also aggregate Amazon SNS log files from multiple AWS regions and multiple AWS accounts
into a single Amazon S3 bucket. For more information, see Aggregating CloudTrail Log Files to a Single
Amazon S3 Bucket.
{
"Records": [
{
"eventVersion": "1.02",
"userIdentity": {
"type":"IAMUser",
"userName":"Bob"
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Bob",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE"
},
"eventTime": "2014-09-30T00:00:00Z",
"eventSource": "sns.amazonaws.com",
"eventName": "ListTopics",
"awsRegion": "us-west-2",
"sourceIPAddress": "127.0.0.1",
"userAgent": "aws-sdk-java/unknown-version",
"requestParameters": {
"nextToken": "ABCDEF1234567890EXAMPLE=="
},
"responseElements": null,
"requestID": "example1-b9bb-50fa-abdb-80f274981d60",
"eventID": "example0-09a3-47d6-a810-c5f9fd2534fe",
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
},
{
"eventVersion": "1.02",
"userIdentity": {
"type":"IAMUser",
"userName":"Bob"
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Bob",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE"
},
"eventTime": "2014-09-30T00:00:00Z",
"eventSource": "sns.amazonaws.com",
"eventName": "CreateTopic",
"awsRegion": "us-west-2",
"sourceIPAddress": "127.0.0.1",
"userAgent": "aws-sdk-java/unknown-version",
"requestParameters": {
"name": "hello"
},
"responseElements": {
"topicArn": "arn:aws:sns:us-west-2:123456789012:hello-topic"
},
"requestID": "example7-5cd3-5323-8a00-f1889011fee9",
"eventID": "examplec-4f2f-4625-8378-130ac89660b1",
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
},
{
"eventVersion": "1.02",
"userIdentity": {
"type":"IAMUser",
"userName":"Bob"
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Bob",
"accountId": "123456789012",
"accessKeyId": "AKIAIOSFODNN7EXAMPLE"
},
"eventTime": "2014-09-30T00:00:00Z",
"eventSource": "sns.amazonaws.com",
"eventName": "DeleteTopic",
"awsRegion": "us-west-2",
"sourceIPAddress": "127.0.0.1",
"userAgent": "aws-sdk-java/unknown-version",
"requestParameters": {
"topicArn": "arn:aws:sns:us-west-2:123456789012:hello-topic"
},
"responseElements": null,
"requestID": "example5-4faa-51d5-aab2-803a8294388d",
"eventID": "example8-6443-4b4d-abfd-1b867280d964",
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
},
]
}
HTTP/HTTPS Headers
When Amazon SNS sends a subscription confirmation, notification, or unsubscribe confirmation message
to HTTP/HTTPS endpoints, it sends a POST message with a number of Amazon SNS-specific header
values.You can use these header values to do things such as identify the type of message without having
to parse the JSON message body to read the Type value.
x-amz-sns-message-type
The type of message. The possible values are SubscriptionConfirmation, Notification,
and UnsubscribeConfirmation.
x-amz-sns-message-id
A Universally Unique Identifier, unique for each message published. For a notification that Amazon
SNS resends during a retry, the message ID of the original message is used.
x-amz-sns-topic-arn
The Amazon Resource Name (ARN) for the topic that this message was published to.
x-amz-sns-subscription-arn
The ARN for the subscription to this endpoint.
The following HTTP POST header is an example of a header for a Notification message to an HTTP
endpoint.
POST / HTTP/1.1
x-amz-sns-message-type: Notification
x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf3905c3-41de-beaa-fcfcc21c8f55
Content-Length: 1336
Content-Type: text/plain; charset=UTF-8
Host: myhost.example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
MessageId
A Universally Unique Identifier, unique for each message published. For a message that Amazon
SNS resends during a retry, the message ID of the original message is used.
Signature
Base64-encoded "SHA1withRSA" signature of the Message, MessageId, Type, Timestamp, and
TopicArn values.
SignatureVersion
Version of the Amazon SNS signature used.
SigningCertURL
The URL to the certificate that was used to sign the message.
SubscribeURL
The URL that you must visit in order to confirm the subscription. Alternatively, you can instead use
the Token with the ConfirmSubscription action to confirm the subscription.
Timestamp
The time (GMT) when the subscription confirmation was sent.
Token
A value you can use with the ConfirmSubscription action to confirm the subscription. Alternatively,
you can simply visit the SubscribeURL.
TopicArn
The Amazon Resource Name (ARN) for the topic that this endpoint is subscribed to.
Type
The type of message. For a subscription confirmation, the type is SubscriptionConfirmation.
The following HTTP POST message is an example of a SubscriptionConfirmation message to an HTTP
endpoint.
POST / HTTP/1.1
x-amz-sns-message-type: SubscriptionConfirmation
x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
Content-Length: 1336
Content-Type: text/plain; charset=UTF-8
Host: myhost.example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
{
"Type" : "SubscriptionConfirmation",
"MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
"Token" :
"2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582af
bacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL
included in this message.",
"SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscrip
tion&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTop
ic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582af
bacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
"Timestamp" : "2012-04-26T20:45:04.751Z",
"SignatureVersion" : "1",
"Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNK
WLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvol
IC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
"SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationSer
vice-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
}
You can download the following JSON file to view the definition of the JSON format for a subscription
confirmation: https://sns.us-west-2.amazonaws.com/doc/2010-03-31/SubscriptionConfirmation.json.
"SignatureVersion" : "1",
"Signature" : "EXAMPLEw6JRNwm1LFQL4ICB0bnXrdB8ClRMTQFGBqwLp
GbM78tJ4etTwC5zU7O3tS6tGpey3ejedNdOJ+1fkIp9F2/LmNVKb5aFlYq+9rk9ZiPph5YlLmWsD
cyC5T+Sy9/umic5S0UQc2PEtgdpVBahwNOdMW4JPwk0kAJJztnc=",
"SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationSer
vice-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
"UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&Sub
scriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998413945fb5a96"
}
You can download the following JSON file to view the definition of the JSON format for a notification:
https://sns.us-west-2.amazonaws.com/doc/2010-03-31/Notification.json.
MessageId
A Universally Unique Identifier, unique for each message published. For a message that Amazon
SNS resends during a retry, the message ID of the original message is used.
Signature
Base64-encoded "SHA1withRSA" signature of the Message, MessageId, Type, Timestamp, and
TopicArn values.
SignatureVersion
Version of the Amazon SNS signature used.
SigningCertURL
The URL to the certificate that was used to sign the message.
SubscribeURL
The URL that you must visit in order to re-confirm the subscription. Alternatively, you can instead
use the Token with the ConfirmSubscription action to re-confirm the subscription.
Timestamp
The time (GMT) when the unsubscribe confirmation was sent.
Token
A value you can use with the ConfirmSubscription action to re-confirm the subscription. Alternatively,
you can simply visit the SubscribeURL.
TopicArn
The Amazon Resource Name (ARN) for the topic that this endpoint has been unsubscribed from.
Type
The type of message. For a unsubscribe confirmation, the type is UnsubscribeConfirmation.
The following HTTP POST message is an example of a UnsubscribeConfirmation message to an HTTP
endpoint.
POST / HTTP/1.1
x-amz-sns-message-type: UnsubscribeConfirmation
x-amz-sns-message-id: 47138184-6831-46b8-8f7c-afc488602d7d
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf3905c3-41de-beaa-fcfcc21c8f55
Content-Length: 1399
Content-Type: text/plain; charset=UTF-8
Host: myhost.example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
{
"Type" : "UnsubscribeConfirmation",
"MessageId" : "47138184-6831-46b8-8f7c-afc488602d7d",
"Token" : "2336412f37fb687f5d51e6e241d09c805a5a57b30d712f7948a98bac386ed
fe3e10314e873973b3e0a3c09119b722dedf2b5e31c59b13ed
bb26417c19f109351e6f2169efa9085ffe97e10535f4179ac1a03590b0f541f209c190f9ae23219ed6c470453e06c19b5ba9fcbb27daeb7c7",
"TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
"Message" : "You have chosen to deactivate subscription arn:aws:sns:us-west2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55.\nTo cancel this
operation and restore the subscription, visit the SubscribeURL included in this
message.",
"SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscrip
tion&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTop
ic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f7948a98bac386ed
fe3e10314e873973b3e0a3c09119b722dedf2b5e31c59b13ed
bb26417c19f109351e6f2169efa9085ffe97e10535f4179ac1a03590b0f541f209c190f9ae23219ed6c470453e06c19b5ba9fcbb27daeb7c7",
"Timestamp" : "2012-04-26T20:06:41.581Z",
"SignatureVersion" : "1",
"Signature" : "EXAMPLEHXgJmXqnqsHTlqOCk7TIZsnk8zpJJoQbr8leD+8kAHcke3ClC4VPOvd
pZo9s/vR9GOznKab6sjGxE8uwqDI9HwpDm8lGxSlFGuwCruWeecnt7MdJCNh0XK4XQCbtGoXB762ePJ
faSWi9tYwzW65zAFU04WkNBkNsIf60=",
"SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationSer
vice-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
}
You can download the following JSON file to view the definition of the JSON format for an unsubscribe
confirmation: https://sns.us-west-2.amazonaws.com/doc/2010-03-31/UnsubscribeConfirmation.json.
Use the following JSON format for the value of the AttributeValue parameter.
{
"healthyRetryPolicy" : {
"minDelayTarget" : <int>,
"maxDelayTarget" : <int>,
"numRetries" : <int>,
"numMaxDelayRetries" : <int>,
"backoffFunction" : "<linear|arithmetic|geometric|exponential>"
},
"throttlePolicy" : {
"maxReceivesPerSecond" : <int>
}
}
Use the following JSON format for the value of the AttributeValue parameter.
{
"http" : {
"defaultHealthyRetryPolicy" : {
"minDelayTarget": <int>,
"maxDelayTarget": <int>,
"numRetries": <int>,
"numMaxDelayRetries": <int>,
"backoffFunction": "<linear|arithmetic|geometric|exponential>"
},
"disableSubscriptionOverrides" : <boolean>,
"defaultThrottlePolicy" : {
"maxReceivesPerSecond" : <int>
}
}
}
For more information about the SetTopicAttribute action, go to SetTopicAttributes in the Amazon Simple
Notification Service API Reference.
Sign in to the AWS Management Console and open the Amazon SNS console at https://
console.aws.amazon.com/sns/.
2.
Select a topic that is subscribed to either an Amazon SQS endpoint or an HTTP/S endpoint and then
click the topic ARN.
3.
4.
Document History
The following table describes the important changes to the documentation since the last release of the
Amazon SNS Developer Guide.
API version: 2010-03-31
Latest documentation update: September 23, 2015
Change
Description
Date Changed
Platform endpoints
and device tokens
Application event
notifications
Added a topic about how to trigger notifications when cer- September 23, 2015
tain application events occur. For more information, see
Application Event Notifications (p. 93).
Added a topic on using Amazon SNS topic attributes for April 09, 2015
message delivery status. For more information, see Using
Amazon SNS Topic Attributes for Message Delivery
Status (p. 161).
Added a topic on using Amazon SNS application attributes February 05, 2015
for message delivery status. For more information, see
Using Amazon SNS Application Attributes for Message
Delivery Status (p. 90).
Change
Description
Date Changed
Added a topic on logging Amazon SNS API calls by using October 09, 2014
CloudTrail. For more information, see Logging Amazon
Simple Notification Service API Calls By Using AWS
CloudTrail (p. 171).
Added a topic about the high-level steps you must perform October 09, 2014
to use Amazon SNS mobile push. This information should
help you gain a better understanding of the steps involved
when using the Amazon SNS mobile push APIs. For more
information, see Amazon SNS Mobile Push HighLevel
Steps (p. 38).
Support for authen- Updated a topic on how to send authenticated messages August 19, 2014
ticated messages
with MPNS. For more information, see Getting Started with
with Microsoft Push MPNS (p. 72).
Notification Service
for Windows Phone
Support for setting
a Time To Live
(TTL) message attribute for mobile
push notification
messages
Added a topic on how to specify expiration metadata for July 10, 2014
a mobile push notification message. For more information,
see Using the Amazon SNS Time To Live (TTL) Message
Attribute for Mobile Push Notifications (p. 95).
Added topics on how to use Baidu, MPNS, and WNS, with June 12, 2014
Amazon SNS to send push notification messages to mobile
devices. For more information, see Getting Started with
Baidu Cloud Push (p. 50), Getting Started with
MPNS (p. 72), and Getting Started with WNS (p. 75).
Message attributes
Amazon SNS
samples in Java
Added a section about using the AWS SDK for Java with April 23, 2014
Amazon SNS. Examples in this section show how to create
a new Amazon SNS client, set the Amazon SNS endpoint
to use, and create a new topic. In addition, examples are
provided on how to subscribe to, publish to, and delete a
topic. For more information, see Using the AWS SDK for
Java with Amazon SNS (p. 8).
Mobile push notifica- Added a topic about how to create and send custom plat- December 17, 2013
tions
form-specific payloads in messages to mobile devices.
For more information, see Send Custom Platform-Specific
Payloads in Messages to Mobile Devices (p. 88).
Mobile push notifica- Added support to send notification messages directly to
tions
apps on mobile devices. For more information, see
Amazon SNS Mobile Push Notifications (p. 36).
Initial Release
May 1, 2013