I try to send SMS(Text message) to a specific mobile number(MA : Morocco, FROM : Morocco) using AWS SNS service using nodeJs I get a success and the data looks like:
{"MessageID":"ea4cf.."}
However, the SMS does not get delivered.
Here is the code:
router.post('/send-text', (req, res) => {
var dynamoDBConfiguration = {
apiVersion: '2010-03-31',
accessKeyId: 'A...',
secretAccessKey: '...',
region: 'eu-west-3'
};
AWS.config.update(dynamoDBConfiguration);
// Create publish parameters
var params = {
Message: req.body.message,
PhoneNumber: '+' + req.body.number,
MessageAttributes: {
'AWS.SNS.SMS.SenderID': {
'DataType': 'String',
'StringValue': req.body.subject,
}
}
};
// Create promise and SNS service object
var publishTextPromise = new AWS.SNS({ apiVersion: '2010-03-31' }).publish(params).promise();
publishTextPromise.then(
function (data) {
res.end(JSON.stringify({ MessageID: data.MessageId }));
}).catch(
function (err) {
res.end(JSON.stringify({ Error: err }));
});