[英]AWS Lambda Function is returning Handler 'handler' missing on module 'index'
Consider following code - 考虑以下代码 -
function index(event, context, callback) {
//some code
}
exports.handler = index();
{
"errorMessage": "Handler 'handler' missing on module 'index'"
}
This is my function which is having business logic. 这是我的功能,它具有业务逻辑。 My javascript file name is index.js
. 我的javascript文件名是index.js
。
Whenever I test this code on aws lambda, It gives following log(failed)
. 每当我在aws lambda上测试这段代码时,它会给出以下log(failed)
。
This is a screenshot of the Amazon Lambda Upload Site: 这是亚马逊Lambda上传网站的屏幕截图:
In export.handler
, you are not referencing the index
function, but the result of its execution. 在export.handler
,您没有引用index
函数,而是它的执行结果。 I guess you want to export the function itself. 我想你想要导出函数本身。
let index = function index(event, context, callback) {
//some code
}
exports.handler = index;
Or maybe directly 或者直接
exports.handler = function index(event, context, callback) {
//some code
}
What you can do is to declare your function as the exports.handler. 你可以做的是将你的函数声明为exports.handler。 When your function exports to lambda, it comes with the namespace. 当您的函数导出到lambda时,它带有命名空间。
exports.handler = function(event, context) {
//code
}
You can ignore the callback if you want fast code. 如果需要快速代码,可以忽略回调。
您可能错误地将处理程序指定为“index.js”而不是“index.handler”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.