Failed to import module into lambda

I have a simple export.js file, and I zipped up the folder and uploaded it to Lambda, but at runtime it throws 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 greatly appreciated. Thanks

+5
source share
3 answers

1.Enter the file export.js

2.Find the handler in the file, export.handler

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

3. Set the handler in the lambda configuration for export.handler

4. Only lock the contents of the folder if you also zip the folder and it does not find your file.

5. Register the zip file export.zip

+2
source

Include the node_modules directory in the directory. Replace the index.js + node_modules and load.

0
source

I have a similar experience. Although what I did was serverless, but I think the error is still relevant, because it also comes from AWS lambda. This is the error 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 use webpack and I solved this by deleting the library in my webpack.config.js and the library name is self explanatory.

what I did was delete this line from webpack.config.js:

 const nodeExternals = require("webpack-node-externals"); 

Please let me know if you need more information. thank you

-1
source

Source: https://habr.com/ru/post/1244613/


All Articles