Parsing Amazon SNS message formats
Amazon SNS uses the following formats.
Topics
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 header values for such tasks as identifying
the message type without having to parse the JSON message body to read the
Type
value. By default, Amazon SNS sends all the notification to HTTP/S
endpoints with Content-Type
set to text/plain; charset=UTF-8
.
To choose a Content-Type
other than text/plain (default), see
headerContentType
in Creating an HTTP/S delivery policy.
x-amz-sns-message-type
-
The type of message. The possible values are
SubscriptionConfirmation
,Notification
, andUnsubscribeConfirmation
. x-amz-sns-message-id
-
A Universally Unique Identifier (UUID), 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:2bcfbf39-05c3-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
HTTP/HTTPS subscription confirmation JSON format
After you subscribe an HTTP/HTTPS endpoint, Amazon SNS sends a subscription confirmation
message to the HTTP/HTTPS endpoint. This message contains a SubscribeURL
value that you must visit to confirm the subscription (alternatively, you can use the
Token
value with the ConfirmSubscription
).
Note
Amazon SNS doesn't send notifications to this endpoint until the subscription is confirmed
The subscription confirmation message is a POST message with a message body that contains a JSON document with the following name-value pairs.
Type
-
The type of message. For a subscription confirmation, the type is
SubscriptionConfirmation
. MessageId
-
A Universally Unique Identifier (UUID), unique for each message published. For a message that Amazon SNS resends during a retry, the message ID of the original message is used.
Token
-
A value you can use with the
ConfirmSubscription
action to confirm the subscription. Alternatively, you can simply visit theSubscribeURL
. TopicArn
-
The Amazon Resource Name (ARN) for the topic that this endpoint is subscribed to.
Message
-
A string that describes the message. For subscription confirmation, this string looks like this:
You have chosen to subscribe to the topic arn:aws:sns:us-east-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.
SubscribeURL
-
The URL that you must visit in order to confirm the subscription. Alternatively, you can instead use the
Token
with theConfirmSubscription
action to confirm the subscription. Timestamp
-
The time (GMT) when the subscription confirmation was sent.
SignatureVersion
-
Version of the Amazon SNS signature used.
-
If the
SignatureVersion
is 1,Signature
is a Base64-encodedSHA1withRSA
signature of theMessage
,MessageId
,Type
,Timestamp
, andTopicArn
values. -
If the
SignatureVersion
is 2,Signature
is a Base64-encodedSHA256withRSA
signature of theMessage
,MessageId
,Type
,Timestamp
, andTopicArn
values.
-
Signature
-
Base64-encoded
SHA1withRSA
orSHA256withRSA
signature of theMessage
,MessageId
,Type
,Timestamp
, andTopicArn
values. SigningCertURL
-
The URL to the certificate that was used to sign the message.
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" : "2336412f37...", "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic", "Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.", "SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37...", "Timestamp" : "2012-04-26T20:45:04.751Z", "SignatureVersion" : "1", "Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=", "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem" }
HTTP/HTTPS notification JSON format
When Amazon SNS sends a notification to a subscribed HTTP or HTTPS endpoint, the POST message sent to the endpoint has a message body that contains a JSON document with the following name-value pairs.
Type
-
The type of message. For a notification, the type is
Notification
. MessageId
-
A Universally Unique Identifier (UUID), unique for each message published. For a notification that Amazon SNS resends during a retry, the message ID of the original message is used.
TopicArn
-
The Amazon Resource Name (ARN) for the topic that this message was published to.
Subject
-
The
Subject
parameter specified when the notification was published to the topic.Note
This is an optional parameter. If no
Subject
was specified, then this name-value pair does not appear in this JSON document. Message
-
The
Message
value specified when the notification was published to the topic. Timestamp
-
The time (GMT) when the notification was published.
SignatureVersion
-
Version of the Amazon SNS signature used.
-
If the
SignatureVersion
is 1,Signature
is a Base64-encodedSHA1withRSA
signature of theMessage
,MessageId
,Subject
(if present),Type
,Timestamp
, andTopicArn
values. -
If the
SignatureVersion
is 2,Signature
is a Base64-encodedSHA256withRSA
signature of theMessage
,MessageId
,Subject
(if present),Type
,Timestamp
, andTopicArn
values.
-
Signature
-
Base64-encoded
SHA1withRSA
orSHA256withRSA
signature of theMessage
,MessageId
,Subject
(if present),Type
,Timestamp
, andTopicArn
values. SigningCertURL
-
The URL to the certificate that was used to sign the message.
UnsubscribeURL
-
A URL that you can use to unsubscribe the endpoint from this topic. If you visit this URL, Amazon SNS unsubscribes the endpoint and stops sending notifications to this endpoint.
The following HTTP POST message is an example of a Notification
message
to an HTTP endpoint.
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:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96 Content-Length: 773 Content-Type: text/plain; charset=UTF-8 Host: myhost.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!", "Timestamp" : "2012-05-02T00:54:06.655Z", "SignatureVersion" : "1", "Signature" : "EXAMPLEw6JRN...", "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem", "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96" } }
HTTP/HTTPS unsubscribe confirmation JSON format
After an HTTP/HTTPS endpoint is unsubscribed from a topic, Amazon SNS sends an unsubscribe confirmation message to the endpoint.
The unsubscribe confirmation message is a POST message with a message body that contains a JSON document with the following name-value pairs.
Type
-
The type of message. For a unsubscribe confirmation, the type is
UnsubscribeConfirmation
. MessageId
-
A Universally Unique Identifier (UUID), unique for each message published. For a message that Amazon SNS resends during a retry, the message ID of the original message is used.
Token
-
A value you can use with the
ConfirmSubscription
action to re-confirm the subscription. Alternatively, you can simply visit theSubscribeURL
. TopicArn
-
The Amazon Resource Name (ARN) for the topic that this endpoint has been unsubscribed from.
Message
-
A string that describes the message. For unsubscribe confirmation, this string looks like this:
You have chosen to deactivate subscription arn:aws:sns:us-east-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55.\nTo cancel this operation and restore the subscription, visit the SubscribeURL included in this message.
SubscribeURL
-
The URL that you must visit in order to re-confirm the subscription. Alternatively, you can instead use the
Token
with theConfirmSubscription
action to re-confirm the subscription. Timestamp
-
The time (GMT) when the unsubscribe confirmation was sent.
SignatureVersion
-
Version of the Amazon SNS signature used.
-
If the
SignatureVersion
is 1,Signature
is a Base64-encodedSHA1withRSA
signature of theMessage
,MessageId
,Type
,Timestamp
, andTopicArn
values. -
If the
SignatureVersion
is 2,Signature
is a Base64-encodedSHA256withRSA
signature of theMessage
,MessageId
,Type
,Timestamp
, andTopicArn
values.
-
Signature
-
Base64-encoded
SHA1withRSA
orSHA256withRSA
signature of theMessage
,MessageId
,Type
,Timestamp
, andTopicArn
values. SigningCertURL
-
The URL to the certificate that was used to sign the message.
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:2bcfbf39-05c3-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" : "2336412f37...", "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic", "Message" : "You have chosen to deactivate subscription arn:aws:sns:us-west-2: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=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37fb6...", "Timestamp" : "2012-04-26T20:06:41.581Z", "SignatureVersion" : "1", "Signature" : "EXAMPLEHXgJm...", "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem" }
SetSubscriptionAttributes delivery policy JSON format
If you send a request to the SetSubscriptionAttributes
action and set the
AttributeName
parameter to a value of DeliveryPolicy
, the
value of the AttributeValue
parameter must be a valid JSON object. For
example, the following example sets the delivery policy to 5 total retries.
http://sns.us-east-2.amazonaws.com/ ?Action=SetSubscriptionAttributes &SubscriptionArn=arn%3Aaws%3Asns%3Aus-east-2%3A123456789012%3AMy-Topic%3A80289ba6-0fd4-4079-afb4-ce8c8260f0ca &AttributeName=DeliveryPolicy &AttributeValue={"healthyRetryPolicy":{"numRetries":5}} ...
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 }, "requestPolicy" : { "headerContentType" : "text/plain | application/json | application/xml" } }
For more information about the SetSubscriptionAttribute
action, go to
SetSubscriptionAttributes in the Amazon Simple Notification Service API Reference. For
more information on the supported HTTP content-type headers, see Creating an HTTP/S delivery policy.
SetTopicAttributes delivery policy JSON format
If you send a request to the SetTopicAttributes
action and set the
AttributeName
parameter to a value of DeliveryPolicy
, the
value of the AttributeValue
parameter must be a valid JSON object. For
example, the following example sets the delivery policy to 5 total retries.
http://sns.us-east-2.amazonaws.com/ ?Action=SetTopicAttributes &TopicArn=arn%3Aaws%3Asns%3Aus-east-2%3A123456789012%3AMy-Topic &AttributeName=DeliveryPolicy &AttributeValue={"http":{"defaultHealthyRetryPolicy":{"numRetries":5}}} ...
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 }, "defaultRequestPolicy" : { "headerContentType" : "text/plain | application/json | application/xml" } } }
For more information about the SetTopicAttribute
action, go to SetTopicAttributes in the
Amazon Simple Notification Service API Reference. For more information on the supported HTTP
content-type headers, see Creating an HTTP/S delivery policy.