我通过 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/