Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws-lambda Cannot find module

I keep getting this error in the aws-lambda console when uploading code from a zip file. I have tried uploading other zip files and they work correctly. The .js file is named "CreateThumbnail.js" in the zip file. I believe the handler is also named properly "CreateThumbnail.handler". the node_modules subdirectory is also setup. Anyone have any idea?

{   "errorMessage": "Cannot find module 'CreateThumbnail'",   "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)"   ] } 
like image 901
Daniel Munoz Avatar asked Jun 06 '15 02:06

Daniel Munoz


People also ask

Can not find module AWS Lambda?

The "Cannot find module" occurs when a lambda function is trying to access a module which is not available in the function's execution runtime. The most common causes for the error are: zipping the wrong files, e.g. zipping a directory instead of the contents of the directory.

How do I resolve the unable to import module error that I receive when I run Lambda code in Python?

To resolve this error, create a deployment package or Lambda layer that includes the libraries that you want to use in your Python code for Lambda. Important: Make sure that you put the library that you import for Python inside the /python folder.


1 Answers

The way I was able to get this to work was:

  1. Name the file exports.js
  2. Name the handler, within the file, exports.handler
  3. Set the handler in the lambda config to exports.handler
  4. Zip up only the contents of the folder, not the folder itself (as mentioned above) and rename the zip file exports.zip
like image 181
Aaron Avatar answered Sep 29 '22 13:09

Aaron