1
votes

How to set a sender while sending sms from AWS SNS service?

Checking the docs for SNS about sending SMS https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/sns-examples-sending-sms.html#sending-sms-getattributes

And also here https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property

With these docs combined I can send a sms but the sender remains unset. Why?

var AWS = require('aws-sdk');
AWS.config.update({ region: 'eu-west-1' });

var params = {
    Message: 'TEXT_MESSAGE', 
    PhoneNumber: '+44123456780',
    MessageAttributes: {
        'SenderID': {
            DataType: "String",
            StringValue: "Company1",
        }
    }
};


var publishTextPromise = new AWS.SNS().publish(params).promise();


publishTextPromise.then(
    function (data) {
        console.log("MessageID is " + data.MessageId);
    }).catch(
        function (err) {
            console.error(err, err.stack);
        });

I can send a sms except I cannot see a way to set a sender. How do I set a sender for each message?

1
Did you check the AWS link on region/countries that supports Senderid as per docs.aws.amazon.com/sns/latest/dg/… ? - v.j

1 Answers

1
votes

I added following section under params for Node.js code and sender id works

    MessageAttributes:{
        "AWS.SNS.SMS.SenderID" : {
            DataType: "String",
            StringValue: "abc"
        }
    },

Note that senderId works for countries/regions as defined in AWS documentation: https://docs.aws.amazon.com/sns/latest/dg/sns-supported-regions-countries.html#sms-support-note-1