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.