最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Send SMS with AWS Javascript SDK - Stack Overflow

programmeradmin8浏览0评论

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.

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.

Share Improve this question asked Aug 3, 2016 at 23:28 ozzieisaacsozzieisaacs 8432 gold badges12 silver badges23 bronze badges 7
  • The code looks correct. Are you perhaps using an old version of the AWS SDK? – Mark B Commented Aug 3, 2016 at 23:44
  • @user3345171 Should that AWS.SNS(); be AmazonSNSClient(); ? – Piyush Patil Commented Aug 3, 2016 at 23:48
  • @error2007s no, this is JavaScript, you seem to be trying to convert it to Java. – Mark B Commented Aug 3, 2016 at 23:51
  • That was it Mark. Thank you very much! – ozzieisaacs Commented Aug 3, 2016 at 23:51
  • 1 @user3345171 what version did you end up using? I've tried not setting the version and also setting it to '2010-03-31' - both times I get the error about Unexpected key 'PhoneNumber' found in params. Can you update your question with the correct code? Or did you have to do something specific on the console? – Brent Commented Sep 21, 2016 at 3:08
 |  Show 2 more comments

2 Answers 2

Reset to default 9

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!

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

发布评论

评论列表(0)

  1. 暂无评论