node.js - 获取 AWS SMS 的发送状态

标签 node.js amazon-web-services sms aws-sdk amazon-sns

我通过 Node SDK 从 AWS 发送短信。短信发送良好,我正在尝试获取送货信息。显然这并不容易,必须设置 SNS 以将日志发送到 CloudWatch 并解析 CloudWatch 以获取查找 MessageId 的传递信息:https://stackoverflow.com/a/40327061/2054629

如果我通过 SNS Web 界面发送短信,日志我会在 cloudwatch 中看到日志,但当我通过 Node SDK 发送时看不到日志。在从 Node 发送之前,我无法获得有关如何设置的信息。

理想情况下,我想实现以下目标:

const sendSMS = async (message, number) => {
    // send the SMS
    // wait to get delivery info
    // resolve with delivery info, or reject if failed
}

目前我有:

import AWS from 'aws-sdk';

AWS.config.update({
  accessKeyId: accessKey,
  secretAccessKey: secretKey,
  region: 'us-east-1',
});

const sns = new AWS.SNS();

const sendSMS = async (message, number) => {
  return await new Promise((resolve, reject) => {
    sns.publish({
      Message: message,
      MessageStructure: 'string',
      PhoneNumber: number,
    }, (err, res) => {
      if (err) { return reject(err); }
      resolve(res);
    });  
  });
}

仅向 AWS 发送 SMS 请求并通过类似的方式解决

{
  ResponseMetadata: { RequestId: '7e0999a3-xxxx-xxxx-xxxx-xxxxxxxxxxxx' },
  MessageId: 'f7f21871-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
}

我不确定是否必须设置一个 SNS 应用程序才能获取日志,我不想让事情变得简单。

最佳答案

您可能已经这样做了,但要为 SMS 传送配置 cloudwatch 日志,您必须配置 SMS 首选项。为此,您需要创建一个 IAM 角色以允许 cloudwatch 日志访问。通过 AWS 控制台非常简单。步骤在 http://docs.aws.amazon.com/sns/latest/dg/sms_preferences.html

如果需要,您甚至可以控制记录成功交付 + 失败 SMS 的百分比。完成此操作后,无论您以何种方式发送 SMS,您都应该开始查看 cloudwatch 日志。

我想将此添加为评论,但我没有足够的代表。如果它不起作用,我会删除这个答案。

关于node.js - 获取 AWS SMS 的发送状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600479/

相关文章:

node.js - Node.js 中有查看我当前目录的命令吗?

amazon-web-services - 如何动态添加/验证域和电子邮件地址到亚马逊 SES?

amazon-web-services - 从子域重定向到域(AWS、Route53)

安卓:接收短信

java - 在给定日期发送自动消息

node.js - 通过 CRON 在设定的时间运行 Node JS 应用程序,还是本质上利用 CRON 运行 24/7 Node 应用程序,哪个效率更高?

angularjs - 第一次运行 Angular 4 Web 应用程序项目后显示空白屏幕

javascript - 使用 Chokidar 忽略多个文件

amazon-web-services - 如何检测 puppet 运行是否完成

sms - 如何批量重发失败短信