Skip to content

How do I access Amazon SNS topic delivery logs for push notifications?

4 minute read
0

I want to access Amazon Simple Notification Service (Amazon SNS) topic delivery logs for push notifications.

Short description

Amazon SNS provides support to log the delivery status of push notification messages published to SNS topics. After you configure delivery status logging, Amazon SNS sends log entries for push notifications to Amazon CloudWatch Logs. Logging message delivery status gives the following operational insights:

  • Confirm whether Amazon SNS successfully delivers messages to the endpoint.
  • Identify the response sent from the push notification service provider to Amazon SNS.
  • Measure the message dwell time. Message dwell time is the time between the publish timestamp and before handing off to the push notification service provider.

Configure push notification delivery status logs

The following section provides steps to configure delivery status logging using the AWS Management Console. You can also use AWS SDKs or the AWS Command Line Interface (AWS CLI) command set-platform-application-attributes to configure message delivery logs.

Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Complete the following steps:

  1. Open the Amazon SNS console.

  2. On the navigation menu, expand Mobile, and then choose Push notifications.

  3. In the Platform applications section, select the platform application that you want to have delivery status for.

  4. Choose Edit.

  5. Expand Delivery status logging - optional.

  6. For Success sample rate, enter the percentage of successful messages that you want to receive in CloudWatch Logs. By default, Amazon SNS logs all failed deliveries.

  7. In the IAM roles section, for Service role, select Create new service role, and then choose Create and use new service roles. The AWS Identity and Access Management (IAM) console opens.

    Note: If you already have an IAM role with valid permissions, then select Use existing service role to use that service role instead.

  8. On the IAM console permission request page, choose Allow to give Amazon SNS write access to use CloudWatch Logs on your behalf.

  9. After your return to the Amazon SNS console, choose Save changes.

This creates an IAM role for successful and failed deliveries, with the following policy and trust relationships for Amazon SNS.

IAM role for successful deliveries:

arn:aws:iam::1111111111:role/SNSSuccessFeedbackA2P-your-region-your-id

IAM role for failed deliveries:

arn:aws:iam::1111111111:role/SNSFailureFeedbackA2P-your-region-your-id

Policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents",
        "logs:PutMetricFilter",
        "logs:PutRetentionPolicy"
      ],
      "Resource": [
        "arn:aws:logs:your-region:your-account-id:log-group:sns/your-region/your-account-id/app/your-platform/your-app-name:*"
      ]
    }
  ]
}

Trust relationships:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sns.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
    "StringEquals": {
        "aws:SourceAccount": "your-account-id"
        },
        "ArnEquals": {
            "aws:SourceArn": "arn:aws:sns:your-region:your-account-id:app/your-platform/your-app-name"
        }
      }
    }
  ]
}

View push notification delivery status logs

Note: Push notification delivery status logs appear only after a successful or failed delivery. The success group appears after the first successful delivery, and the failure group appears after a failed delivery.

  1. Open the Amazon CloudWatch console.

  2. On the navigation pane, expand Logs, and then choose Log Management.

  3. In the Filter search box, enter sns to find only log groups for Amazon SNS.

  4. The sns/your-AWS-region/your-account_ID/app/platform_name/application_name log group includes the successful delivery logs.

    sns/us-east-1/1111111111/app/GCM/Test1
    sns/us-east-1/1111111111/app/APNS_SANDBOX/Test2
    sns/us-east-1/1111111111/app/APNS/Test3
  5. The sns/your-AWS-region/your-account_ID/app/platform_name/application_name**/Failure** log group contains the failure delivery logs:

    sns/us-east-1/1111111111/app/GCM/Test1/Failure
    sns/us-east-1/1111111111/app/APNS_SANDBOX/Test2/Failure
    sns/us-east-1/1111111111/app/APNS/Test3/Failure
  6. Choose the Amazon SNS log group that you want to view.

  7. On the Log streams tab, choose a particular log stream to view the application endpoint delivery logs.

  8. To see the delivery status of your message, expand the log event and check providerResponse. For a list of push notification service response codes, see Platform response codes.

Related information

How do I troubleshoot FCM mobile push notification failures in Amazon SNS?

How do I troubleshoot APNs mobile push notification failures in Amazon SNS?

Amazon SNS mobile app attributes