amazon-snsaws-lambdaamazon-echo

AWS Lambda calling SNS


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);
    });
}

Solution

  • 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!