Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting delivery status of AWS SMS

I'm sending sms from AWS through the node SDK. SMS are going out well and I'm trying to get delivery informations. Apparently it's not that easy and one has to setup SNS to send logs to Cloudwatch and to parse CloudWatch to get the delivery information looking up the MessageId: https://stackoverflow.com/a/40327061/2054629

If I send sms through SNS web interface, logs I see logs in cloudwatch, but not when I send them through the node SDK. I could not get information on how to setup things before sending them from node.

Ideally, I want to achieve something like:

const sendSMS = async (message, number) => {
    // send the SMS
    // wait to get delivery info
    // resolve with delivery info, or reject if failed
}

Currently I have:

import AWS from 'aws-sdk';

AWS.config.update({
  accessKeyId: accessKey,
  secretAccessKey: secretKey,
  region: 'us-east-1',
});

const sns = new AWS.SNS();

const sendSMS = async (message, number) => {
  return await new Promise((resolve, reject) => {
    sns.publish({
      Message: message,
      MessageStructure: 'string',
      PhoneNumber: number,
    }, (err, res) => {
      if (err) { return reject(err); }
      resolve(res);
    });  
  });
}

which only send a SMS request to AWS and resolves with something like

{
  ResponseMetadata: { RequestId: '7e0999a3-xxxx-xxxx-xxxx-xxxxxxxxxxxx' },
  MessageId: 'f7f21871-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
}

I'm not sure if one has to setup an SNS application to be able to get logs or not, and I'd rather not to keep things simple.

like image 263
Guig Avatar asked Apr 25 '17 02:04

Guig


People also ask

Does AWS SNS guaranteed delivery?

Q: Does Amazon SNS guarantee that messages are delivered to the subscribed endpoint? Yes, as long as the subscribed endpoint is accessible. A message delivery fails when Amazon SNS can't access a subscribed endpoint, due to either a client-side or a server-side error.

How do I get notifications from AWS?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to enable events for. Choose Properties. Navigate to the Event Notifications section and choose Create event notification.

How long do messages stay in AWS SNS?

SNS : Push Mechanism — SNS pushes messages to consumers. SQS : Messages are persisted for some duration is no consumer available. The retention period value is from 1 minute to 14 days. The default is 4 days.


1 Answers

You might have already done this but to configure cloudwatch logs for SMS deliveries, you have to configure SMS preferences. For that you need to create an IAM role to allow cloudwatch logs access. It is very simple to do it through AWS console. The steps are given at http://docs.aws.amazon.com/sns/latest/dg/sms_preferences.html

You can even control what percentage of successful deliveries + failed SMSs are logged if you want. Once this is done, you should start seeing cloudwatch logs whichever way you sent the SMS.

I wanted to add this as a comment but I don't have enough rep. I'll delete this answer if it doesn't work.

like image 200
user818510 Avatar answered Oct 10 '22 14:10

user818510