AWS Lambda Error: "Cannot find module '/var/task/index'" AWS Lambda Error: "Cannot find module '/var/task/index'" node.js node.js

AWS Lambda Error: "Cannot find module '/var/task/index'"


Fixed it! My issue was that I tried to zip the file using my Mac's built-in compression function in Finder.

If you're a Mac user, like me, you should run the following script in terminal when you are in the root directory of your project (folder containing your index.js, node_modules, etc. files).

zip -r ../yourfilename.zip *

For Windows:

Compress-Archive -LiteralPath node_modules, index.js -DestinationPath yourfilename.zip


Update to the accepted answer: When this error occurs, it means your zip file is not in the valid form which AWS requires.

If you double click on zip you will find your folder inside that your code file,but lambda wants that when you double click on zip it shoud show direct code files.

To achieve this:

open terminal  cd your-lambda-folder zip -r index.zip *

Then, upload index.zip to AWS Lambda.


Check that file name and handler name are same:

In this case we expect that all our code will be in <code>bundle.ls</code> file

That means that zip file has bundle.js file that exports handler function:

exports.handler = (event, context, callback) => {//...}