Skip to content

lukehedger/yarn-workspace-lambda-layer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yarn workspaces X Lambda Layers

Yarn workspaces simplify working with monorepos. Dependencies for all "workspaces" in a monorepo are hoisted to a shared node_modules at the root of a project - this avoids duplication and speeds up installations. Workspaces can also depend on other workspaces, making it trivial to share common utilities across your monorepo.

Lambda layers can be used to distribute shared dependencies to your Lambda functions. Dependencies do not need to be shipped with the Lambda deployment package, meaning smaller Lambdas and reduced invocation times.

Yarn workspaces and Lambda layers can be combined to provide a seamless dependency workflow across local and remote environments. Dependency management is centralised and standardised. Lambda code can be compiled (when using TypeScript, Babel etc) without needing a module bundler (like Rollup or Webpack).

Features

  • Install all monorepo dependencies locally and in CI with a single command: yarn install
  • Build all workspaces locally and in CI with a single command: yarn build
  • Test all workspaces locally and in CI with a single command: yarn test
  • Install only production dependencies (local and 3rd party) to the Lambda Layer: yarn layer (the magic happens in this script ✨)
  • Lambda layer imports /opt/nodejs/ can be mapped to local directories when working with TypeScript or Jest
  • Bonus: Compose Lambdas and layers using the AWS CDK

Example

This repo demonstrates the use of Yarn workspaces with Lambda layers using two Lambdas (lambda-a and lambda-b), one shared NPM package (date-fns), one local utility (util-logger) and one Lambda layer (lambda-layer).

yarn-workspace-lambda-layer-example