Skip to content

How do I access Amazon SNS topic delivery logs for SMS messages?

3 minute read
3

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

Resolution

Configure SMS delivery status attributes for Amazon CloudWatch Logs

Complete the following steps:

  1. Open the Amazon SNS console.
  2. On the navigation pane, expand Mobile, and then select Text messaging (SMS).
  3. In the Text messaging preferences section, choose Edit.
  4. Expand Delivery status logging - optional.
  5. For Success sample rate, in the % text box, enter 100.
    Note: Success rate is the percentage of successful message deliveries to log.
  6. In the IAM roles section, for Service role, select Create new service role, and then choose Create new roles. The AWS Identity and Access Management (IAM) console opens.
    Note: If you already have an IAM role with the correct permissions, then choose Use existing service role instead.
  7. On the IAM console permission request page, choose Allow.
  8. After you return to the Amazon SNS console, choose Save changes.

An IAM role for successful and failed deliveries is created, with the following policy and trust relationships for Amazon SNS.

IAM role:

arn:aws:iam::1111111111:role/SNSSuccessFeedback

Policy:

{  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents",
        "logs:PutMetricFilter",
        "logs:PutRetentionPolicy"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

Trust relationships:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "sns.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

View delivery status logs

Complete the following steps:

  1. Open the Amazon CloudWatch console.

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

  3. In the Filter search box, enter DirectPublishToPhoneNumber to find only SMS log groups for Amazon SNS.
    Note: It can take up to 72 hours for delivery logs to appear in the Amazon SNS console based on the destination phone number's carrier.
    For example:
    The sns/your-AWS-region/your-AWS-account-ID/DirectPublishToPhoneNumber log group contains the successful delivery logs:

    sns/us-east-1/1111111111/DirectPublishToPhoneNumber
    

    Example for successful delivery logs:

    {
        "notification": {
            "messageId": "34d9b400-c6dd-5444-820d-fbeb0f1f54cf",
            "timestamp": "2016-06-28 00:40:34.558"
        },
        "delivery": {
            "phoneCarrier": "My Phone Carrier",
            "mnc": 270,
            "destination": "+1XXX5550100",
            "priceInUSD": 0.00645,
            "smsType": "Transactional",
            "mcc": 310,
            "providerResponse": "Message has been accepted by phone carrier",
            "dwellTimeMs": 599,
            "dwellTimeMsUntilDeviceAck": 1344
        },
        "status": "SUCCESS"
    }

    The sns/your-AWS-region/your-AWS-account-ID/DirectPublishToPhoneNumber/Failure log group contains the failure delivery logs:

    sns/us-east-1/1111111111/DirectPublishToPhoneNumber/Failure

    Example for failure delivery logs:

    {
        "notification": {
            "messageId": "1077257a-92f3-5ca3-bc97-6a915b310625",
            "timestamp": "2016-06-28 00:40:34.559"
        },
        "delivery": {
            "mnc": 0,
            "destination": "+1XXX5550100",
            "priceInUSD": 0.00645,
            "smsType": "Transactional",
            "mcc": 0,
            "providerResponse": "Unknown error attempting to reach phone",
            "dwellTimeMs": 1420,
            "dwellTimeMsUntilDeviceAck": 1692
        },
        "status": "FAILURE"
    }
  4. Choose the SNS log group that you want to view.

  5. On the Log streams tab, choose a particular log stream to view the SMS delivery logs.

  6. To view the delivery status of your SMS message, expand the log event and check providerResponse.

View opted-out phone numbers

Recipients can opt out of receiving SMS messages on their phones from their AWS account. For more information, see Opting out of receiving SMS messages.

Complete the following steps:

  1. Open the Amazon SNS console.
  2. On the navigation pane, expand the Mobile section, and then choose Text Messaging (SMS).
  3. To view opted-out phone numbers, go to the Opted-out phone numbers section.

Related information

Monitoring Amazon SNS topics using CloudWatch

Setting SMS messaging preferences in Amazon SNS

Amazon SNS SMS delivery monitoring with Amazon CloudWatch metrics and logs