AWS Lambda – cannot find module (based on handler)

Error in the Execution Result

<pre>
Response:
{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'decode-verify-jwt'",

Response:
{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'decode-verify-jwt'",
</pre>

and also the following text appears:

<pre>    
   Lambda can't find the file decode-verify-jwt.js. Make sure that your handler upholds the format: file-name.method.
</pre>

Solution

I uploaded the file by using a zip. I zipped the parent directory, so my starting module was not in the root directory, but one level under that.

So there are two ways to fix it:
1) Include the parent directory on the “Handler”.
example parentDirectoryName/decode-verify-jwt.handler

2) Rebuild your zip without the parent directory and upload the zip again.

Overall, it’s a mismatch between the handler and the code in your directory structure.

Uncategorized  

Leave a Reply