Search⌘ K
AI Features

Sharing Behaviour

Explore the three main strategies for sharing behavior among AWS Lambda functions, including common libraries, Lambda layers, and invoking functions from one another. Understand the trade-offs in latency, deployment consistency, cross-language sharing, and complexity. This lesson helps you design efficient, maintainable serverless applications by choosing the appropriate method to share code and behavior effectively.

As you start breaking down an application into Lambda functions, some of those functions will need to share behaviours. There are currently three options for that with Lambda functions:

  • Common libraries
  • Lambda layers
  • Invoking one function from another

These options differ primarily in four aspects:

  • Latency to execute shared code
  • Runtime or deployment-time consistency
  • Sharing across programming language runtimes
  • Deployment speed and complexity

Bundling shared libraries #

The first option is to extract common code into a shared programming language library and bundle it with each function. This minimises the latency to execute shared code, since it’s just a quick in-memory call. Bundling dependencies with a function makes deployment simpler, but provides only deployment-time consistency. If you deploy just one function after changing the common code, all other functions will still run with the previous version. Common dependencies increase the package size for each function, so this is a good choice for typical programming language libraries, but may not be the best option for bundling a 100 MB native binary for a function that needs to redeploy frequently.

Shared libraries do ...