This article talks about a way to package multiple Lambda functions into a npm module. The module is deployed as an AWS Lambda layer, and function are
required from the layer.
In an AWS ecosystem, Lambda fns form the foundation of server-less architecture or Function as a Service (FaaS). Server-less does not mean there are no servers involved, but one don't provision or manage the servers on which the functions execute. This arrangement makes sense for many workloads.
The template below is a way to develop and package a node module, that can be easily deployed to AWS. AWS layer requires us to upload a zip with all dependencies (node_modules/*). So we don't get a chance to run npm install in AWS.
The trick here is to create a local npm module that can be installed locally using
npm pack. Then we go on to create a new empty npm module (
npm init) and install the package we just created. This will install our module along with its dependencies in
node_modules folder. Zip the new module starting from root and it is ready for upload to AWS Lambda.
Now in AWS start creating the functions. Lambda fn1 will be a single liner.
exports.handler = require('lambdas').fn1;