AWS Lambda Layers and local dev

Hi all,

Just started using Serverless and loving it. I’m working on a project that uses an existing AWS Layer. My development environment is (usually) Windows which causes problems with some compiled node modules. In production, this is resolved by the Layer but in the dev environment, I need a way to use the local non-layer-ified equivalent library.

I’ve included the library under devDependencies which keeps sls deploy happy. What I really need are 2 different node_modules: One for the local equivalent of layer-ified modules, and one for all others.

Unfortunately, the dep in question has a massive amount of dependencies itself, so an exclude rule would barely make a dent.

So, to boil it down:

  1. What’s the correct way to handle code provided by external layers when testing locally?
  2. What’s the best way to separate a subset of local and production dependencies? Is devDependencies enough in this case?

Thanks!

4 Likes

I’m not entirely sure how to handle layers locally. I’m working on some ideas tho.

It’s not the prettiest thing but here’s what I’ve been using:

const layerPath = process.env.LAYER_PATH || '../layers/dplib/';
const doLambda = require(layerPath + 'dolambda');

And then in serverless.yml:

  environment:
    LAYER_PATH: '/opt/dplib/'
1 Like

Hey uclaeagit,

Would you be able to share a bit more about your setup? It’s a pretty good solution for our project but am I right in thinking that ‘require’ only accepts literal strings and can’t be altered dynamically?

Thanks!

1 Like