0

I have one Lambda function which needs to invoke another lambda (InvocationType is set to 'Event'). I am calling invokeActionProcessor function (see below) to invoke this second lambda. When I test the code using AWS console, I see that I am calling the lambda.invoke (log statement before invoke is logging) but I don't see any invocation happening when I check the logs for the second lambda in cloudwatch management console. Trying to find out what might be the issue.

Note that first lambda is using IAM role that has "AWSLambdaFullAccess" policy attached. I checked various other similar threads on this topic but didn't see answer so posting this question.

function invokeActionProcessor(functionName, message) {
    const payload = {
        operation: PROCESS_MESSAGE,
        message,
    };
    const params = {
        FunctionName: functionName,
        InvocationType: 'Event',
        Payload: new Buffer(JSON.stringify(payload)),
    };
    return new Promise((resolve, reject) => {
        console.log("invokeActionProcessor: invoking the function " + functionName);
        try {
            Lambda.invoke(params, function(err, data) {
                if(err) {
                    console.log("invokeActionProcessor: got error: " + err);
                    reject(err);
                } else {
                    console.log("invokeActionProcessor: success, " + data);
                    resolve(null, data);
                }
            });
        } catch (err) {
            console.log("invokeActionProcessor: got exception - " + err);
        } 
    });
}
mi10
  • 213
  • 3
  • 14
  • yes, that thread answered my question. Thanks for pointing to that thread (somehow it didn't show up in my search). Looks like if we put lambdas in VPC (which we have to do as we are also accessing elasticache in the same VPC), we have to incur the cost of NAT gateways. Will have to look at what is more cost effective - NAT gateways in two subnets or using SNS for invoking another lambda... – mi10 May 09 '17 at 17:04
  • Let me know on your conclusion I'm interested. – johni May 09 '17 at 17:05
  • Thinking about it, how would you send trigger SNS from that lambda? Same issue. – johni May 09 '17 at 17:09
  • yes, running into the same issue. So looks like NAT gateways is only way to go if lambda has to be in vpc. and we need to put them in vpc because we need to access elasticache which is inaccessible if we don't put the lambda in vpc. :-( – mi10 May 10 '17 at 05:13
  • You could use S3 supported VPC endpoint for putting dummy files which in turn will trigger another lambda to do your thing. Not sure what's the prices for using S3 endpoints - let me know (it's a bit ugly, but might be cost effective) – johni May 10 '17 at 07:27
  • that is certainly a good idea. event dynamodb entry can be created for this trigger since dynamo db also provide vpc end point. By the way, after adding NAT gateway, I was able to invoke lambda from another lambda and also was able to invoke it via SNS. – mi10 May 10 '17 at 21:44
  • Of course, that's what my answer is all about :) but that's. going to cost additional charges for the traffic going through the NAT. What about the "hack" I suggested? Let me know how it went and if it is cheaper solution. – johni May 11 '17 at 00:09

0 Answers0