1

What is the way to send sms using aws-sdk-js ? https://github.com/aws/aws-sdk-js

Is there is proper code available from amazon for this(javascript). I refered the below docs, but is not enough informative https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SMS.html

This code actually worked for me.

const AWS = require('aws-sdk');
AWS.config.update({
    region: 'ap-southwest-1',
    accessKeyId: 'XXXXXXXXXXXXXXXXXXXX',
    secretAccessKey: 'xxxxSSSSXXXXXXXXXXXXXXXXXXXXXXXXXX'
});

var sns = new AWS.SNS();

var params = {
    Message: 'Alert! emssage.....',
    MessageStructure: 'string',
    PhoneNumber: 'XXXXXXXXXXXX'
};

sns.publish(params, function (err, data) {
    if (err) console.log(err, err.stack);
    else console.log(data);
});

Any better way of doing this with adding Sender ID and all?

shijin
  • 2,998
  • 1
  • 24
  • 30

2 Answers2

1

You can create a SNS topic and subscribe to a Mobile number. Then you can use SDK to publish the topic. This way you can send SMS.

Visit Send SMS using AWS SDK example given in java.

You can refer this link for Node.js publish sns

PublishRequest _PublishRequest = null;
    PublishResult _PublishResult = null;
    try{
        _PublishRequest = new PublishRequest("arn:aws:sns:us-east-1:081701745661:sendSMS","MessageBody","Subject");
        _PublishResult = SNSClient.publish(_PublishRequest);
        }catch(Exception e){
            System.out.println("Got an error in method sendSMSNotification: " + e.getMessage());                
        }
    return _PublishResult.getMessageId();
Surajit Kundu
  • 455
  • 1
  • 7
  • 17
  • Actually I was in search of a stable NodeJS code, not JAVA. Java code is readily available in website.\ – shijin Nov 15 '17 at 09:21
1

How about

var params = {
    Message: 'Alert! emssage.....',
    MessageStructure: 'string',
    PhoneNumber: 'XXXXXXXXXXXX',
    'AWS.SNS.SMS.SenderID': {
        DataType: 'String',
        StringValue: 'XXXXXXXXXXXX'
    }
};`

But pls sure that you're in supporting country.
You can check here

Zero0Ho
  • 166
  • 1
  • 1
  • 9