Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 525
Ashly Avatar asked May 09 '16 13:05

Ashly


People also ask

What should a Lambda handler return?

When you call it, Lambda waits for the event loop to be empty and then returns the response or error to the invoker. The response object must be compatible with JSON. stringify . For asynchronous function handlers, you return a response, error, or promise to the runtime instead of using callback .

How do I add a handler in Lambda?

This function handler name reflects the function name ( lambda_handler ) and the file where the handler code is stored ( lambda_function.py ). To change the function handler name in the Lambda console, on the Runtime settings pane, choose Edit.

How do you call a function in Lambda handler?

You can invoke Lambda functions directly using the Lambda console, a function URL HTTP(S) endpoint, the Lambda API, an AWS SDK, the AWS Command Line Interface (AWS CLI), and AWS toolkits.

Can Lambda continue after returning response?

Lambda manages the function's asynchronous event queue and attempts to retry on errors. If the function returns an error, Lambda attempts to run it two more times, with a one-minute wait between the first two attempts, and two minutes between the second and third attempts.


1 Answers

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 } 
like image 122
Alexis N-o Avatar answered Sep 21 '22 19:09

Alexis N-o