3

Our services currently utilize AWS' SNS SMS for sending transactional texts to users (i.e., account confirmation, password resets, etc.). We also have at least two environments--Dev and Production--using the same SNS SMS service since both environments run in the same AWS account and region.

We are working on recording SMS bounce info in our database by ingesting the CloudWatch failure logs via Lambda; however, we have no way of differentiating bounces from Dev for testing purposes vs. legit bounces in Production from users based on those logs.

The goal is to be able to differentiate the bounces by environment so we can properly record them in the respective DBs; however, I am not seeing any way to do that in SNS or CloudWatch other than using separate accounts or potentially other regions.

Is anyone aware of a way to accomplish our goal without having to resort to separate accounts or even regions?

CHB
  • 51
  • 4
  • Can't you use to different SMS end points and designate one for dev and one for production? – Rodrigo Murillo Nov 15 '17 at 23:12
  • How do you create new/different SMS endpoints? As far as I could tell, you only have one SMS endpoint, at least per region in AWS. – CHB Nov 21 '17 at 16:00
  • Sorry I mean a different custom sender ID - can't you send a different one for each environment? https://stackoverflow.com/questions/38355151/how-to-send-an-sms-with-custom-sender-id-with-amazon-sns-and-python-and-boto3 – Rodrigo Murillo Nov 21 '17 at 17:31
  • Not sure if that data would end up in the logs however. – Rodrigo Murillo Nov 21 '17 at 17:32
  • @RodrigoM Good thought, but the CloudWatch logs do not appear to include the SenderID: `{ "notification": { "messageId": "XXX", "timestamp": "2017-11-21 17:49:40.643" }, "delivery": { "destination": "+XXXXXXXXXXX", "priceInUSD": 0, "smsType": "Transactional", "providerResponse": "Phone is currently unreachable/unavailable", "dwellTimeMs": 251, "dwellTimeMsUntilDeviceAck": 517 }, "status": "FAILURE" }` – CHB Nov 22 '17 at 18:31
  • Seems like you need to store each message id in a DB table with the environment that it originates from. Then the bounce handler will be able to look up the message id – Rodrigo Murillo Nov 23 '17 at 15:37
  • .. and identify its originating environment – Rodrigo Murillo Nov 23 '17 at 15:50

2 Answers2

0

Every time you send a SMS through AWS SNS, you can store the results in a PublishResult object, which contains the message ID of your message, as seen in the following example code taken from SNS Documentation:

public static void main(String[] args) {
    AmazonSNSClient snsClient = new AmazonSNSClient();
    String message = "My SMS message";
    String phoneNumber = "+1XXX5550100";
    Map<String, MessageAttributeValue> smsAttributes = 
        new HashMap<String, MessageAttributeValue>();
        //<set SMS attributes>
        sendSMSMessage(snsClient, message, phoneNumber, smsAttributes);
}

public static void sendSMSMessage(AmazonSNSClient snsClient, String message, 
    String phoneNumber, Map<String, MessageAttributeValue> smsAttributes) {
    PublishResult result = snsClient.publish(new PublishRequest()
                        .withMessage(message)
                        .withPhoneNumber(phoneNumber)
                        .withMessageAttributes(smsAttributes));
    System.out.println(result); // Prints the message ID.
}

Console output: {MessageId: 9b888f80-15f7-5c30-81a2-c4511a3f5229}

How you use this information depends on many considerations, such as the number of hosts running your code in your production and development environments, how quick you want to access this data after you send a message, data retention, scalability, and how you are planning to store your CloudWatch logs.

Possible solution:

A solution would depend on your needs. AWS has a myriad of data storage solutions that can be used to store your message ID; simple storage (S3), NoSQL databases (such as DynamoDB), and even data warehouse cluster solutions (like AWS Redshift). One example is to stream your data using Kinesis Firehose into an S3 bucket with your message ID (and any other relevant information you might want to store at the time of your publish) as a serialized JSON object. This has the advantage that it's very low on cost, and you can easily query your S3 objects using AWS Athena.

Depending how you use and access your CloudWatch logs, other DBs might be more suitable.

Disclosure: I work at the AWS team responsible for SMS messaging.

pnv
  • 231
  • 1
  • 6
-1

Frankly speaking you have to handle it on your own through code using message ID as stated above by Aws guy.

This is simple use case,I don't understand why AWS can support it.