从节点包功能调用Lambda

编程入门 行业动态 更新时间:2024-10-28 12:30:53
本文介绍了从节点包功能调用Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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

本文发布于:2023-10-29 12:51:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   功能   Lambda

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!