Skip to content

Instantly share code, notes, and snippets.

@sohamdodia
Last active May 29, 2018 09:29
Show Gist options
  • Save sohamdodia/7f077d6aced597e519bdeae876ee86d2 to your computer and use it in GitHub Desktop.
Save sohamdodia/7f077d6aced597e519bdeae876ee86d2 to your computer and use it in GitHub Desktop.
Code snippet to send sms using AWS SNS.
const AWS = require('aws-sdk');
AWS.config.update({
region: 'region', //https://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html follow this link for supported region
accessKeyId: 'access key',
secretAccessKey: 'secret key'
});
const sns = new AWS.SNS();
const params = {
Message: 'Your OTP is 123456',
MessageStructure: 'string',
PhoneNumber: '+91XXXXXXXXX',
MessageAttributes: {
'AWS.SNS.SMS.SMSType': {
DataType: 'String',
StringValue: 'Transactional' //[Transactional or promotional]
},
'AWS.SNS.SMS.SenderID': {
DataType: 'String',
StringValue: 'Test'
}
}
};
sns.publish(params, (err, data) => {
if (err) {
console.log(err, err); // an error occurred
} else {
console.log('success', data); // successful response
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment