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

Using Amazon SNS Application Attributes for Message Delivery Status

Amazon Simple Notification Service (Amazon SNS) provides support to log the delivery status of push notification messages. After you configure application attributes, log entries will be sent to CloudWatch Logs for messages sent from Amazon SNS to mobile endpoints. Logging message delivery status helps provide better operational insight, such as the following:

  • Know whether a push notification message was delivered from Amazon SNS to the push notification service.

  • Identify the response sent from the push notification service to Amazon SNS.

  • 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.

Configuring Message Delivery Status Attributes with the AWS Management Console

You can configure message delivery status attributes with the AWS Management Console.

  1. Sign in to the AWS Management Console and open the Amazon SNS console at https://console.aws.amazon.com/sns/v2/home.

  2. In the left Navigation pane, click Apps, and then click the app containing the endpoints for which you want receive CloudWatch Logs.

  3. Click Application Actions and then click Delivery Status.

  4. On the Delivery Status dialog box, click Create IAM Roles.

    You will then be redirected to the IAM console.

  5. Click Allow to give Amazon SNS write access to use CloudWatch Logs on your behalf.

  6. 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.

Amazon SNS Message Delivery Status CloudWatch Log Examples

After you configure message delivery status attributes for an application endpoint, CloudWatch Logs will be generated. Example logs, in JSON format, are shown as follows:

SUCCESS

Copy
{ "status": "SUCCESS", "notification": { "timestamp": "2015-01-26 23:07:39.54", "messageId": "9655abe4-6ed6-5734-89f7-e6a6a42de02a" }, "delivery": { "statusCode": 200, "dwellTimeMs": 65, "token": "Examplei7fFachkJ1xjlqT64RaBkcGHochmf1VQAr9k-IBJtKjp7fedYPzEwT_Pq3Tu0lroqro1cwWJUvgkcPPYcaXCpPWmG3Bqn-wiqIEzp5zZ7y_jsM0PKPxKhddCzx6paEsyay9Zn3D4wNUJb8m6HXrBf9dqaEw", "attempts": 1, "providerResponse": "{\"multicast_id\":5138139752481671853,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1422313659698010%d6ba8edff9fd7ecd\"}]}", "destination": "arn:aws:sns:us-east-1:111122223333:endpoint/GCM/GCMPushApp/c23e42de-3699-3639-84dd-65f84474629d" } }

FAILURE

Copy
{ "status": "FAILURE", "notification": { "timestamp": "2015-01-26 23:29:35.678", "messageId": "c3ad79b0-8996-550a-8bfa-24f05989898f" }, "delivery": { "statusCode": 8, "dwellTimeMs": 1451, "token": "examp1e29z6j5c4df46f809505189c4c83fjcgf7f6257e98542d2jt3395kj73", "attempts": 1, "providerResponse": "NotificationErrorResponse(command=8, status=InvalidToken, id=1, cause=null)", "destination": "arn:aws:sns:us-east-1:111122223333:endpoint/APNS_SANDBOX/APNSPushApp/986cb8a1-4f6b-34b1-9a1b-d9e9cb553944" } }

For a list of push notification service response codes, see Platform Response Codes.

Configuring Message Delivery Status Attributes with the AWS SDKs

The AWS SDKs provide APIs in several languages for using message delivery status attributes with Amazon SNS.

The following Java example shows how to use the SetPlatformApplicationAttributes API to configure application attributes for message delivery status of push notification messages. You can use the following attributes for message delivery status: SuccessFeedbackRoleArn, FailureFeedbackRoleArn, and SuccessFeedbackSampleRate. The SuccessFeedbackRoleArn and FailureFeedbackRoleArn attributes are used to give Amazon SNS write access to use CloudWatch Logs on your behalf. The SuccessFeedbackSampleRate attribute is for specifying the sample rate percentage (0-100) of successfully delivered messages. After you configure the FailureFeedbackRoleArn attribute, then all failed message deliveries generate CloudWatch Logs.

Copy
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.setPlatformApplicationArn("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.

Platform Response Codes

The following is a list of links for the push notification service response codes:

Push Notification Service Response Codes
Amazon Device Messaging (ADM) See Response Format in Sending a Message via Amazon Device Messaging
Apple Push Notification Service (APNS) See HTTP/2 Response from APNs in Communicating with APNs.
Google Cloud Messaging for Android (GCM) See Downstream message error response codes in the GCM Connection Server Reference
Microsoft Push Notification Service for Windows Phone (MPNS) See Push Notification Service response codes
Windows Push Notification Services (WNS) See "Response codes" in Push notification service request and response headers