Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send SMS with AWS Javascript SDK

Tags:

I want to send an SMS with the AWS javascript sdk with a verification code.

var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
var sns = new AWS.SNS();

var params = {
  Message: 'this is a test message',
  MessageStructure: 'string',
  PhoneNumber: '+12346759845'
};

sns.publish(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

I keep getting "Unexpected key \'PhoneNumber\' found in params".

I have followed the examples in the documentation and it seems what I have is valid as far as I can tell. Apparently, I do not need to create a topic to send individual text messages.

like image 389
ozzieisaacs Avatar asked Aug 03 '16 23:08

ozzieisaacs


People also ask

Can we send SMS using JavaScript?

This convenient SMS capability is easy to use from JavaScript, as long as you have the right API. Using SMS for verification usually works like this: Create a unique code that can't be easily guessed. Send that code to the user via SMS text message.

How do I use Amazon SNS to send SMS in Java?

If you want to send a SMS message to a single number you can use the Amazon AWS SDK. Docs are available at http://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html#sms_publish_sdk.


1 Answers

Yes so the correct answer is that an outdated sdk version was used. To fix it set aws-sdk to * in your package.json file and run

npm install aws-sdk

With the latest version this code will run fine!

like image 96
Steeve17 Avatar answered Oct 01 '22 03:10

Steeve17