...

/

Multiple Lambda Functions - Configuring Providers and Plugins

Multiple Lambda Functions - Configuring Providers and Plugins

Learn to package and share code libraries across Lambda functions using Layers.

Introduction

Having gained some basic knowledge of the main components of Serverless and how to deploy our service, let’s gradually build on that knowledge by looking at more advanced configurations and examples.

In this example, we will deploy a service that consists of the following:

  • Two AWS Lambda functions: There is a particular way to organize the folder structure and each function’s dependencies when deploying multiple functions together in one service.

  • Lambda layers: Lambda layers are useful if we have dependencies that are too large in a function or if we have the same dependencies shared among many functions. This saves us deployment time and improves managing and sharing common dependencies.

  • Separate configuration files per environment (config.dev.yml and config.prod.yml): These are very useful when we have different configurations per environment—for example, memory allocation. We currently have two ways we can achieve environment configuration in SLS.

Main serverless.yml components

We'll cover every component of the serverless.yml file in detail to give a full picture of what to pay attention to when creating our own service configuration. Please also note comments and recommendations written directly in the code. The main components we'll use in most of our services are:

Press + to interact
### Section where we define most general settings of our application
org: ORG
app: serverless-101
service: sls-aws-python-starter-extended
frameworkVersion: '3' # We would recommend to go directly for the latest major release, if we're not in need of migrating
provider:
### Section where we define plugins used by our application
plugins:
custom:
### Section where we define different parameters per stage
params:
### Section where we define what files to package
package:
### Section where we define lambda layers
layers:
### Section where we define your functions
functions:
  • org, app, service and frameworkVersion: ...