我有一个我自己无法解决的问题。我的 lambda 函数在本地调用时按预期工作,但从 AWS Lambda 调用时它不发送文本消息。它也不会记录任何错误。
这是我的代码,我只为私人内容加注了星标:
import request from 'request';
import AWS from "aws-sdk";
const options = {***};
const sentAlert = async msg => {
const sns = new AWS.SNS();
await sns.publish({
Message: msg,
PhoneNumber: '***',
MessageAttributes: {
'AWS.SNS.SMS.SenderID': {
'DataType': 'String',
'StringValue': '***'
}
}
}, function (err, data) {
if (err) {
console.log(err.stack);
return;
}
});
console.log('sms sent');
};
export const getAlert = async (event, context, callback) => {
request(options, (err, res, body) => {
if (err) { return console.log('error: ', err); }
if (body.length === 0 ) { return }
console.log(`***`);
const optionsId = {*** };
request(optionsId, (err, res, body) => {
const msg = body.current.indexes[0].description;
console.log('msg: ', msg);
sentAlert(msg);
});
});
};
我使用本地测试它serverless invoke local --function getSmogAlert
,它按预期工作,我从 AWS 获得短信,但是当我用serverless invoke --function getSmogAlert
- 它调用它时,它返回 null 并且不发送任何文本消息。我在使用 Nexmo 时遇到过类似的问题,并认为 AWS.SNS 可能会帮助我,但不是。
请问有什么帮助吗?