Reputation: 4396
I use AWS for sending emails and SMS messages. I know about failed email messages because of the mailer-daemon returned email. Recently, I stopped receiving SMS messages on my text phone, even though the code runs without a problem and I get a message ID for the SMS message. The code publishes an SMS directly to a phone, not to a topic. The Python code is:
import botocore
import boto3
def send_text(message):
boto3.setup_default_session(profile_name='sms')
try:
resource = boto3.resource('sns', region_name="eu-west-1")
response = resource.meta.client.publish(
PhoneNumber=PHONE, Message=message)
message_id = response['MessageId']
print("Published message with text: '%s', id = '%s'." % (message, message_id))
except botocore.exceptions.ClientError:
print("Couldn't publish message.")
raise
and the log shows:
Published message with text: '..', id = 'f4494169-...'.
I checked the CloudWatch console for the relevant region (eu-west-1) and do not see any metrics at all, either for SES or SNS. The docs explain how to monitor publishing to topics, not for direct messages to phones.
How can I debug the SMS sending and check the delivery status with the message ID?
I now see a log group in CloudWatch bearing this name:
arn:aws:logs:eu-west-1:<my AWS id>:log-group:sns/eu-west-1/<my AWS id>/DirectPublishToPhoneNumber:*
The log streams show only successful deliveries and not failed deliveries, even though my code shows the same output for a successful and a failed send.
The issue in my case seems correlated with events in Simple Email Service, such as email bounces and resets. Although I don't understand the reason, the problem goes away after a few days.
I see this graphic on my Console for SNS:
My code shows the same result for both successful and failed sends. The SMS messages are already marked as critical (as opposed to transactional). I did not have events in SES that triggered these failed sends, unlike in previous occurrences, and I do not see links to more information about the failures. How can I debug the reason for failed delivery?
Upvotes: 2
Views: 6725
Reputation: 2822
Delivery status logging can be enabled for SMS direct publishes as well. Please see this link for instructions on how to do so. This setting will emit logs for all SMS sent from your account in the region irregardless of whether they were published through a topic or directly.
Read the details for setting up correctly. The same docs explain the monitoring of the logs:
Open the Amazon CloudWatch console.
On the navigation pane, expand Logs, and then choose Log groups.
Be sure to select the right region at the top right. The graph you showed in your second update is from Amazon SNS; the logs with error messages are on CloudWatch. There you see a log group such as:
sns/eu-west-1/<your ID>/DirectPublishToPhoneNumber/Failure
Click on it and you will see several "Log streams". Click on one and you'll see a message such as this one:
{
"notification": {
"messageId": "<some ID>",
"timestamp": "2021-11-24 09:00:25.193"
},
"delivery": {
"destination": "+100000000",
"smsType": "Transactional",
"providerResponse": "No quota left for account",
"dwellTimeMs": 70
},
"status": "FAILURE"
}
In this case, SNS has a $1/month default quota and you'd have to request an increase with a detailed use case.
Upvotes: 1