serverless-shared-library v0.1.1
Serverless Shared Library
We like to structure our Serverless Framework applications as a directory with multiple services, each representing various silos of functionality. To better facilitate our applications, we needed the ability to share functions and methods between all our services.
Strategy
Because Lambda needs everything packaged nice and neatly into small zip folders that contain each service, this plugin essentially takes your lib
folder and continually syncs it within all your services. In doing so, this plugin also minifies and browserify's your library to keep things fairly optimized. An added benefit is when you're developing, you won't be confused as to what's minified and what's not, so you're constantly aware of where to edit. For i.e., you don't want to be editing any synced and minified lib
code inside your services, because they'll be overwritten by your master lib
directory.
Quick Start
- Create your
lib
folder with an entryindex.js
file, alongside your service directories. - Make sure you include
serverless-shared-library
into yourserverless.yml
andplugins:
markup. - Inside your functions, call
const lib = require('./lib.js')
for full access to your shared library! - Run
serverless offline
orserverless deploy
and your library now lives in your service, but it's all shared! Now go code your heart out.
8 years ago