AWS Lambda调用SNS
问题描述:
我正在与我的Amazon Echo一起玩,并编写了一个小功能,希望在女儿回复后发短信给我.代码执行得很好-但是sns.publish永远不会发生.它无声地失败-我无法引发错误.我相信我拥有适当的IAM权限和主题订阅.有人可以帮忙吗?
I'm playing with my Amazon Echo and wrote a little function which I hope would text me after a response from my daughter. The code executes fine - but the sns.publish never happens. It fails silently - I can't raise an error. I believe I have the proper IAM permissions and Topic subscriptions. Can someone help?
function textMom(kindOfDay){
var message = "Test";
var sns = new AWS.SNS();
console.log("textMethod")
sns.publish({
TopicArn: "arn:aws:sns:us-east-1:",
Message: message
}, function(err, data) {
if(err) {
console.log('error publishing to SNS');
context.fail(err);
} else {
console.log('message published to SNS');
context.done(null, data);
}
console.log(data);
});
}
答
我遇到了同样的问题,并通过将发布参数更改为以下内容来解决了该问题,
I encountered the same problem, and solved by changing publish parameters to below,
sns.publish(params, context.done);
这可以帮助我在所有调用完成之前检查我的功能是否已完成.试试吧!
This help me to check my function is completed before all calls have finished. Try it!