Ashly
Ashly

Reputation: 521

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.

Whenever I test this code on aws lambda, It gives following log(failed).

This is a screenshot of the Amazon Lambda Upload Site: enter image description here

Upvotes: 34

Views: 46785

Answers (3)

rubyisbeautiful
rubyisbeautiful

Reputation: 2121

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

Upvotes: 4

RandomEli
RandomEli

Reputation: 1557

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 = function(event, context) {
    //code
}

You can ignore the callback if you want fast code.

Upvotes: 6

Alexis N-o
Alexis N-o

Reputation: 3993

In export.handler, you are not referencing the index function, but the result of its execution. 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
}

Upvotes: 36

Related Questions