'Runtime.HandlerNotFound aws lambda node.js

"errorType": "Runtime.HandlerNotFound", "errorMessage": "index.handler is undefined or not exported", "trace": [ "Runtime.HandlerNotFound: index.handler is undefined or not exported"...

My aws lambda function is showing this error. The index.js file is in the root folder, handler is the name of the function as well. I tried with the smallest piece of code I could find:

exports.handler = function index(event, context, callback) {

  //some code

}

I have tried all the recommendations I have seen so far for this issue. Still nothing seems to work.

The Runtime settings handler has the below value only:

index.handler


Solution 1:[1]

As per index.handler in Runtime Settings:
runtime settings

Ensure you have the file named index.js:
index.js file listing

And you exported it as per documentation (i.e. index.handler, or whatever you have set it to under Runtime settings):
code sample

Sample Lambda applications in Node.js

blank-nodejs – A Node.js function that shows the use of logging, environment variables, AWS X-Ray tracing, layers, unit tests and the AWS SDK.

Before you click on the orange Test button:
Orange test button

Ensure that you have the changes deployed by clicking on the Deploy button:
undeployed button

Once done, you will see the green Changes deployed label and confirmation:
deployed confirmation

Now you can press it and not get an error:
test button

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1