Amazon Simple Notification Service
Developer Guide

Amazon SNS Message Delivery Status

Amazon SNS provides support to log the delivery status of notification messages sent to topics with the following Amazon SNS endpoints:

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

Configuring Delivery Status Logging Using the AWS Management Console

  1. Sign in to the Amazon SNS console.

  2. On the navigation panel, choose Topics.

  3. On the Topics page, choose a topic and then choose Edit.

  4. On the Edit MyTopic page, expand the Delivery status logging section.

  5. Choose the protocols for which you want to log delivery status, for example Lambda.

  6. Enter the Success sample rate (the percentage of successful messages for which you want to receive CloudWatch Logs.

  7. In the IAM roles subsection, do one of the following:

    • To choose an existing service role from your account, choose Use existing service role and then specify IAM roles for successful and failed deliveries.

    • To create a new service role in your account, choose Create new service role, choose Create new roles to define the IAM roles for successful and failed deliveries in the IAM console.

      To give Amazon SNS write access to use CloudWatch Logs on your behalf, choose Allow.

  8. Choose Save changes.

    You can now view and parse the CloudWatch Logs containing the message delivery status. For more information about using CloudWatch, see the CloudWatch Documentation.

Configuring Message Delivery Status Attributes for Topics Subscribed to Amazon SNS Endpoints Using the AWS SDKs

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

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.

AWS SDK examples to Configure Topic Attributes

The following examples show how to configure topic attributes using the Amazon SNS clients that are provided by the AWS SDKs.

AWS SDK for JavaAWS SDK for .NET
AWS SDK for Java

The following Java example shows how to use the SetTopicAttributes API to configure topic attributes for message delivery status of notification messages sent to topics subscribed to Amazon SNS endpoints. In this example, it is assumed that string values have been set for topicArn, attribName, and attribValue.

final static String topicArn = ("arn:aws:sns:us-east-2:123456789012:MyTopic"); final static String attribName = ("LambdaSuccessFeedbackRoleArn"); final static String attribValue = ("arn:aws:iam::123456789012:role/SNSSuccessFeedback");
SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest(); setTopicAttributesRequest.withTopicArn(topicArn); setTopicAttributesRequest.setAttributeName(attribName); setTopicAttributesRequest.setAttributeValue(attribValue);

For more information about the SDK for Java, see Getting Started with the AWS SDK for Java.

AWS SDK for .NET

The following .NET example shows how to use the SetTopicAttributes API to configure topic attributes for message delivery status of notification messages sent to topics subscribed to Amazon SNS endpoints. In this example, it is assumed that string values have been set for topicArn, attribName, and attribValue.

static String topicArn = "arn:aws:sns:us-east-2:123456789012:MyTopic"; static String attribName = "LambdaSuccessFeedbackRoleArn"; String attribValue = "arn:aws:iam::123456789012:role/SNSSuccessFeedback";
SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest { TopicArn = topicArn, AttributeName = attribName, AttributeValue = attribValue };

For more information about the AWS SDK for .NET, see Getting Started with the AWS SDK for .NET.