0

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);
    });
}
Skoua
  • 3,373
  • 3
  • 38
  • 51
theTechGrandma
  • 103
  • 1
  • 13

1 Answers1

1

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!

  • I wish ... it doesn't work. Have you actually been able to get this to work? Get aws lamdba to publish to a sns topic? – theTechGrandma Feb 14 '16 at 01:31
  • Yeah, I can invoke Lambda by AWS IoT then sending SNS by Lambda code, did you try removing the "exports.handler", just run your code by "nodejs index.js"? It's more easy to debug in this way. – Vavrin Chen Feb 15 '16 at 03:42
  • I'll give that a try. – theTechGrandma Feb 15 '16 at 14:32
  • Well I did run it through Node and worked out a few permissions issues (because of node). I get the text message immediately. Running the same code through Lambda - no message. Just to be clear - this is an Alexa Skill configuration. – theTechGrandma Feb 16 '16 at 18:32
  • reference to https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/, a Lambda function can complete in one of three ways: Timeout, Controlled termination, Default termination. So, if your callbacks have finished in a right way, maybe you can try to increase your lambda function's timeout. (default is 3s, I set to 30s) – Vavrin Chen Feb 17 '16 at 03:58
  • I'm marking this as the accepted answer because what I found was that the callback I had was terminating the context before the message was completed. I actually have it working now. Super happy about that. It was driving me crazy! – theTechGrandma Feb 23 '16 at 13:50
  • Great news! Congratulations! – Vavrin Chen Feb 24 '16 at 02:20