AWS Lambda Layers :: How to add and require a simple js file from a lambda layer

Hi Kanes!

Yes, I found a solution, but not using lambda layers.

I kept my custom libs in a folder inside my project and referred to them using relative paths (eg: require(’…/…/…/custom_libs/myLib’).

Later I got another approach, setting a constant with the absolute path for Node that is ‘/var/task’ and appended them in the require path.

Note that you need to use serverless package commands, include and exclude , to insert this folder inside each lambda. Or use webpack as well to do this kind of job.

Cya!

1 Like