Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/index.mjs"

I tried to deploy a simple function using AWS Lambda. However, I got this error even though I set the handler correctly. P/s: I did not use the serverless.yml nor CLI. I deployed it using AWS Lambda interface.

Lambda Handler: functions/fetchNest/handler.fetch

Error:

"errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'handler'",
        "Require stack:",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
        "    at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
        "    at async start (file:///var/runtime/index.mjs:1137:23)",
        "    at async file:///var/runtime/index.mjs:1143:1"
    ]

handler.js

module.exports.fetch = async event => {

  // Get SSM creds.

folder structure

enter image description here

like image 390
Lucas.Pheliny Avatar asked Oct 16 '25 02:10

Lucas.Pheliny


1 Answers

Don't use Compress FileName in MacOS, else you'll end up zipping your files with chaos. Use command zip instead. For example:

zip testFile.zip index.js node_modules utils

This will create the zip file contains all your required sub files and folders. After that you can config your Handler in Lambda like this

testFile/index.hander

like image 156
Lucas.Pheliny Avatar answered Oct 17 '25 14:10

Lucas.Pheliny