subscribe

Using layers with lambda

In this video we look at how to use layers with AWS Lambda functions. (with nodejs)

We look at a demo app which uses two npm modules (axios and image-size) which were installed using npm and are part of the bundle. We then extract these modules into a layer. We attach this layer to our function and import and use the modules we extracted.

It has 2 advantages:

  • it reduces the size of the bundle
  • it makes it possible to re-use the extracted code across several functions.

We also look at how to separate local files and extract them into a layer and then import them from the function.

If you would like to see an example of using layers, check out this video in which we use a layer to install ImageMagick to resize images within a lambda function.