node.js AWS Lambda 函数正在返回模块“索引”上缺少的处理程序“处理程序”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37117274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:11:04  来源:igfitidea点击:

AWS Lambda Function is returning Handler 'handler' missing on module 'index'

node.jsaws-lambda

提问by AShly

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: enter image description here

这是 Amazon Lambda 上传站点的屏幕截图: 在此处输入图片说明

回答by Alexis N-o

In export.handler, you are not referencing the indexfunction, but the result of its execution. I guess you want to export the function itself.

在 中export.handler,您引用的不是index函数,而是其执行的结果。我猜你想导出函数本身。

let index = function index(event, context, callback) {
  //some code
}
exports.handler = index;

Or maybe directly

或者直接

exports.handler = function index(event, context, callback) {
  //some code
}

回答by RandomEli

What you can do is to declare your function as the exports.handler. When your function exports to lambda, it comes with the namespace.

您可以做的是将您的函数声明为exports.handler。当您的函数导出到 lambda 时,它带有命名空间。

exports.handler = function(event, context) {
    //code
}

You can ignore the callback if you want fast code.

如果你想要快速的代码,你可以忽略回调。

回答by rubyisbeautiful

You may have incorrectly specified your handler as "index.js" instead of "index.handler"

您可能错误地将处理程序指定为“index.js”而不是“index.handler”