Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import Module in Lambda

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

like image 555
user1042327 Avatar asked Nov 08 '22 18:11

user1042327


1 Answers

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

like image 193
CaptainTurk Avatar answered Nov 14 '22 22:11

CaptainTurk