0

I am using AWS Lambda in with node.js code to send SMS onto the device. It works plenty of times but sometimes even after the Sucess response message the SMS is not received by device. Below is the code I used:

'use strict';
console.log('Loading function');

var AWS = require("aws-sdk");
var sns = new AWS.SNS();
let doc = require('dynamodb-doc');
var util = require('util');

exports.handler = (event, context, callback) => {
    sendSMS(context);
};

function sendSMS(context) {
    var phone = '+91xxxxxxxxxx';
    var message = "Hi! Just one more way to test the functionality";
    var params = {
        'PhoneNumber': phone,
        'Message': message
    };

    sns.publish(params, function(err, data) {
        if (err) {
            context.fail(err);
        } else {
            console.log(util.inspect(data));
            console.log('Message Sent successfully')
        }
    });
}

Please help me here to find the exact reason for the same and suggest the solution.

GouravJn
  • 246
  • 1
  • 6
  • 18
  • Is your lambda running inside a VPC? – Abhinav Aug 31 '16 at 03:07
  • No @AbhinavI, Actually I have no understanding about VPC, would be better if you can let me know about its imaportance here. – GouravJn Aug 31 '16 at 05:39
  • If the lambda is running inside a VPC, by default it loses internet access. And SNS APIs, along with other AWS APIs require internet access. So a possible scenario could be that your lambda spawned under the subnet that does not have internet access. Since that is not the case here, the only option I can think of is enabling delivery logs. https://aws.amazon.com/about-aws/whats-new/2015/02/05/amazon-sns-adds-delivery-status/ – Abhinav Aug 31 '16 at 06:44
  • please read my answer here for fully understanding the importance of @AbhinavI question. http://stackoverflow.com/questions/39144688/aws-lambda-invoke-not-calling-another-lambda-function-node-js/39206646#39206646 – johni Aug 31 '16 at 10:29
  • Can you show the logs (from `CloudWatch`) of the invocations that did not send the SMS? – johni Aug 31 '16 at 10:31

0 Answers0