我有一个Lambda函数,该函数可以导入具有常用功能的节点包. Lambda 1将消息放入SQS,Lambda 2进行错误日志记录.共享功能之一调用Lambda 2,但第二次调用存在错误.
I have a Lambda function that imports a node package with common functions. Lambda 1 puts messages into SQS, Lambda 2 does error logging. One of the shared functions invokes Lambda 2, but there's an error on that second invocation.
Lambda 1:
exports.handler = function (event, context) { var pnmacCommon = require('./pnmacCommon.js'); //loading node package try { // this part omitted for space var aws = require('aws-sdk'); var sqs = new aws.SQS({ region : 'us-west-2' }); var params = { MessageBody: JSON.stringify(event), QueueUrl: '[url]' }; sqs.sendMessage(params, function(err,data){ if(err) { console.log('error:',"FAIL Send Message: " + err); context.done(err, "ERROR Put SQS"); // ERROR with message pnmacCommon.SvtLogErrorToElmah(application, "FAIL Send Message: " + err, context); }else{ console.log('Message Sent:', queueUrl); console.log('data:',data.MessageId); context.done(null,''); // SUCCESS } } }); } catch (error) { pnmacCommon.SvtLogErrorToElmah(application, 'SVTMessageBus_Client' + error, context); context.done(error, "ERROR put SQS"); }pnmacCommon.js:
pnmacCommon.js:
var SvtLogErrorToElmah = function (application, error, context) { console.log("SvtLogErrorToElmah=" + JSON.stringify(error, null, 2)); // this part omitted for space var aws = require('aws-sdk'); var lambda = new aws.Lambda({region: 'us-west-2' }); lambda.invoke({ FunctionName: "SVTExceptionLogger", Payload: JSON.stringify(message, null, 2) }, function (error2, data) { if (error2) { context.fail(error2); } else { context.fail(error); }); context.done(null, message); } module.exports.SvtLogErrorToElmah = SvtLogErrorToElmah;在Cloudwatch中,我可以看到SvtLogErrorToElmah函数被调用,但是在尝试调用第二个Lambda时失败.错误消息是TypeError: lambda.invoke is not a function.
Looking in Cloudwatch, I can see that the SvtLogErrorToElmah function gets called, but it fails when it tries to invoke the second Lambda. The error message is TypeError: lambda.invoke is not a function.
有什么想法吗?预先谢谢你.
Any ideas? Thank you in advance.
推荐答案我刚刚遇到了与您相同的错误,而对我来说,aws-sdk版本的更新解决了该问题.
I just got the same error that you had, and for me the update of the aws-sdk version resolved the issue.
更新了 package.json [aws-sdk版本]
old(带有"TypeError:lambda.invoke不是函数")
old (with 'TypeError: lambda.invoke is not a function')
"dependencies": { "aws-sdk": "^2.1.17" }到(已修复错误)
"dependencies": { "aws-sdk": "^2.18.0" }更多推荐
从节点包功能调用Lambda
发布评论