Last active
May 29, 2018 09:29
-
-
Save sohamdodia/7f077d6aced597e519bdeae876ee86d2 to your computer and use it in GitHub Desktop.
Code snippet to send sms using AWS SNS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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