ozzieisaacs
ozzieisaacs

Reputation: 843

Send SMS with AWS Javascript SDK

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.

Upvotes: 22

Views: 13016

Answers (2)

Steeve17
Steeve17

Reputation: 492

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!

Upvotes: 9

Ninad Kulkarni
Ninad Kulkarni

Reputation: 476

I faced the same issue. Its because AWS SNS is supported only on certain regions. This link lists the supported regions - https://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html

Upvotes: 0

Related Questions