Serverless Python Dependencies

serverless Github Actions npm

Serverless Framework plugin to automatically add Python dependencies as layers to your functions.

Based on Lovage - a Python-only serverless library that's more RPC-like and less HTTP service oriented.

Install

sls plugin install -n serverless-pydeps

This will automatically add the plugin to your project's package.json and the plugins section of its serverless.yml. That's all you need. There is no need to install or configure anything else, not even Python.

The plugin will automatically create a layer from the dependencies listed in Pipfile or requirements.txt and attach it to all functions with Python runtime when you run sls deploy.

How Does It Work?

Dependencies are collected and packaged in a special Lambda function. This means you won't have to wait on dependencies to download to your local computer, get zipped up, and uploaded back to S3. This makes deployment, and especially updates, really fast. Dependencies will only be built and uploaded when they change. Your code packages will contain your code and nothing else.

Dependencies will be installed by the same system that runs them, so you never have to worry about running the right Python version on the right OS.

Known Limitations

Other Options

serverless-pydepsserverless-python-requirements
SetupInstall pluginInstall plugin, Python, and potentially Docker for consistent requirements
Package speedFast as dependencies are not packaged locallySlow as every code change repackages all dependencies
Upload SpeedNever uploads anything locallyUploads all dependencies on every code change
Supported providersAWSAll providers supported by Serverless (AWS, GCP, Azure, etc.)
Private repositoriesNot supported as dependencies are downloaded in a Lambda functionSupported
Native code dependencies (*.so files)Only supported if dependency has proper binary wheelSupported with custom Dockerfile, dockerExtraFiles, etc.
Local disk usageZeroAll dependencies are cached and also stored in .serverless