I am trying to import custom dependencies from lambda layer but is not working.
Environment: nodejs8.10
I have a layer which consist of following directory structure:
mylayer.zip-
|-nodejs-
|-util.js
Here, util.js has following code:
module.exports = function SomeFunction() {
console.log('Told you This Doesn't work');
}
and in myLambda.js I'm trying to call SomeFunction with following code:
const someFunction = require('/opt/nodejs/util')
exports.handler = async (event) => {
someFunction();
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
But, I'm getting this error:
{
"errorMessage": "Cannot find module '/opt/nodejs/util'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:474:25)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)",
"Object.<anonymous> (/var/task/index.js:1:75)",
"Module._compile (module.js:652:30)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)"
]
}
Thanks in advance.
/optduring runtime