AWS Lambda Function is returning "Cannot find module 'index'" yet the handler in the config is set to index

Andrew Font picture Andrew Font · Jul 28, 2015 · Viewed 30k times · Source

As my title explains I am getting the following error:

 {
  "errorMessage": "Cannot find module 'index'",
  "errorType": "Error",
  "stackTrace": [
    "Function.Module._resolveFilename (module.js:338:15)",
    "Function.Module._load (module.js:280:25)",
    "Module.require (module.js:364:17)",
    "require (module.js:380:17)"
  ]
}

I have tried both solutions provided in creating-a-lambda-function-in-aws-from-zip-file and simple-node-js-example-in-aws-lambda

My config currently looks like:enter image description here

and my file structure is: enter image description here

and my index.js handler function looks like :

exports.handler = function(event, context) {

What else could be causing this issue aside from what was stated in those two answers above? I have tried both solutions and I have also allocated more memory to the function just incase thats why it couldn't run.

EDIT - For the sake of trying, I created an even simpler version of my original code and it looked like this:

var Q = require('q');
var AWS = require('aws-sdk');
var validate = require('lambduh-validate');
var Lambda = new AWS.Lambda();
var S3 = new AWS.S3();




theHandler = function (event, context) {

  console.log =('nothing');

}

exports.handler = theHandler();

And yet still does not work with the same error?

Answer

tahsintahsin picture tahsintahsin · Sep 11, 2015

Try zipping and uploading the contents of the folder lambda-create-timelapse. Not the folder itself.