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

后端 未结 7 1106
青春惊慌失措
青春惊慌失措 2021-01-31 15:51

As my title explains I am getting the following error:

 {
  \"errorMessage\": \"Cannot find module \'index\'\",
  \"errorType\": \"Error\",
  \"stackTrace\": [
          


        
相关标签:
7条回答
  • 2021-01-31 16:34

    I had the same problem sometime ago - I reformatted the code.

    function lambdafunc1(event, context) {
    ...
    ...
    ...
    }
    
    exports.handler = lambdafunc1
    
    0 讨论(0)
  • 2021-01-31 16:38

    If this was unclear for anyone else, here are the steps:

    Step 1 Navigate to the folder of your project, and open that folder so that you are inside the folder:

    Step 2 Select all of the images you want to upload into to Lambda:

    Step 3 Right-click and compress the files you have selected:


    This will give you a .zip file, which is the file you need to upload to Lambda:


    There are a lot of ways to automate this, but this is the manual procedure.

    0 讨论(0)
  • 2021-01-31 16:39

    make sure in your handler following code added

    exports.handler =  (event, context, callback) => {
    ...
    }
    
    0 讨论(0)
  • 2021-01-31 16:44

    The problem occurs when the handler cannot be located in the zip at first level. So anytime you see such error make sure that the file is at the first level in the exploded folder.

    To fix this zip the files and not the folder that has the files.

    0 讨论(0)
  • 2021-01-31 16:46

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

    0 讨论(0)
  • 2021-01-31 16:48

    Correct Lambda function declaration can look like this:

    var func = function(event, context) {
       ...
    };
    
    exports.handler = func;
    

    You may have other syntax errors that prevent the index.js file from being properly ran. Try running your code locally using another file and using the index.js as your own module.

    0 讨论(0)
提交回复
热议问题