简体   繁体   English

使用AWS Javascript SDK发送短信

[英]Send SMS with AWS Javascript SDK

I want to send an SMS with the AWS javascript sdk with a verification code. 我想使用AWS javascript sdk发送带有验证码的短信。

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". 我一直在“params”中找到“意外的密钥\\'PhoneNumber”。

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. 显然,我不需要创建一个主题来发送单个短信。

Yes so the correct answer is that an outdated sdk version was used. 是的,所以正确的答案是使用了过时的sdk版本。 To fix it set aws-sdk to * in your package.json file and run 要修复它,请在package.json文件中将aws-sdk设置为*并运行

npm install aws-sdk npm安装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. 这是因为AWS SNS仅在某些地区受支持。 This link lists the supported regions - https://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html 此链接列出了支持的区域 - https://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM