We have a service within a Backend class, the service looks like:
// Setup AWS SNS
AWS.config.update({
region: \'eu-west-1\',
accessKeyI
If your use case is to deliver single sms to individuals then you don't need to create a topic and delete it afterwards. It's possible to simply send one sms with the following code.
let AWS = require('aws-sdk');
const sns = new AWS.SNS();
exports.handler = function (event, context, callback) {
var params = {
Message: event.message, // your message you would like to send
MessageAttributes: {
'AWS.SNS.SMS.SMSType': {
DataType: 'String',
StringValue: event.messageType // the smsType "Transactional" or "Promotional"
},
'AWS.SNS.SMS.SenderID': {
DataType: 'String',
StringValue: event.messageSender // your senderId - the message that will show up as the sender on the receiving phone
},
},
PhoneNumber: event.phone // the phone number of the receiver
};
sns.publish(params, function (err, data) {
callback(null, {err: err, data: data});
if (err) {
console.log(err);
context.fail(err);
} else {
console.log("Send sms successful to user:", event.phone);
context.succeed(event);
return;
}
});
};
the api endpoint/lambda receives the following body
{
"message": "hey ho I am the sms message.",
"messageType": "Transactional", //or "Promotional"
"messageSender": "Your Brand",
"phone":"+436640339333"
}