6

I have a simple exports.js file and I have zipped the folder and upload it to Lambda but on run time it gives an error:

"errorMessage": "Cannot find module 'exports'",
"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)"
]

Any help would be appreciated. Thanks

Amir
  • 10,600
  • 9
  • 48
  • 75
user1042327
  • 377
  • 1
  • 7
  • 17

3 Answers3

2

1.Name the file exports.js

2.Name the handler, within the file, exports.handler

exports.handler = function (event, context) 
{
    var YourSkill = new YourSkill();
    YourSkill.execute(event, context);
}

3.Set the handler in the lambda config to exports.handler

4.Zip up only the contents of the folder, if you zip the folder as well it will not find your file.

5.Rename the zip file exports.zip

0

Include a directory called node_modules in your directory. Zip the your index.js + the node_modules directory and upload.

-1

I had a similar experience. While what I did is in the serverless I think the error is still relevant because it also comes from AWS Lambda. This is the error that I saw:

Unable to import module 'src/handlers/list': Error
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/task/src/handlers/list.js:400:18)
    at __webpack_require__ (/var/task/src/handlers/list.js:20:30)
    at Object.<anonymous> (/var/task/src/handlers/list.js:370:18)
    at __webpack_require__ (/var/task/src/handlers/list.js:20:30)
    at /var/task/src/handlers/list.js:63:18
    at Object.<anonymous> (/var/task/src/handlers/list.js:66:10)

I am using Webpack and I solved it by removing a library in my webpack.config.js and the library name is self-explanatory.

What I did is removing this line from webpack.config.js:

const nodeExternals = require("webpack-node-externals");
LW001
  • 2,452
  • 6
  • 27
  • 36
surga
  • 1,436
  • 21
  • 25