Speed-up Lambda function deployment with dependency layers built in AWS
Project description
Turbo Layers for CDK
Speed up deployment of Lambda functions by creating dependency layers in AWS instead of locally.
- ⛓️ Easily separate dependency deployment from Lambda code deployment
- 🔁 Never re-package dependencies just because of a small code change
- ☁️ Never download another single dependency package locally again
- 🏋️ Never upload oversized code packages again
- 🌎 Edit your code in the browser -- no more "deployment package too large to enable inline code editing"
- ❌ Uninstall Docker from your laptop and extend your battery life
- ☕ Take shorter coffee breaks when deploying
Supported Lambda runtimes:
- 🐍 Python
- 📜 Node.js
- 💎 Ruby
- ☕ Java
Benchmark
Below are synth and deploy times for a simple Python function with PythonFunction
compared to Turbo Layers. The benchmark ran three times and the best time were taken for each step.
💤 PythonFunction | 🚀 Turbo Layers | 💤 5x PythonFunction | 🚀 5x Functions w/ Shared Turbo Layer | |
---|---|---|---|---|
Initial Synth | 1:21 | 0:06 | 2:43 | 0:06 |
Initial Deploy | 1:18 | 2:05 | 2:10 | 2:06 |
Code Change Synth | 0:31 | 0:06 | 1:21 | 0:06 |
Code Change Deploy | 0:49 | 0:29 | 1:19 | 0:36 |
New Dependency Synth | 0:33 | 0:06 | 1:30 | 0:06 |
New Dependency Deploy | 0:52 | 1:50 | 1:31 | 1:50 |
As you can see, code changes synth much faster and deploy a bit faster too. Dependency changes take longer to deploy, but are assumed to be way less frequent than code changes. The more dependencies your function uses, the better the results will be.
To run the benchmark yourself use:
npm run bundle && npm run benchmark
API
The best way to browse API documentation is on Constructs Hub. It is available in all supported programming languages.
Installation
-
Confirm you're using CDK v2
-
Install the appropriate package
-
pip install cloudsnorkel.cdk-turbo-layers
-
npm i @cloudsnorkel/cdk-turbo-layers
-
<dependency> <groupId>com.cloudsnorkel</groupId> <artifactId>cdk.turbo-layers</artifactId> </dependency>
-
go get github.com/CloudSnorkel/cdk-turbo-layers-go/cloudsnorkelcdkturbolayers
-
dotnet add package CloudSnorkel.Cdk.TurboLayers
-
Example
const packager = new PythonDependencyPackager(this, 'Packager', {
runtime: lambda.Runtime.PYTHON_3_9,
type: DependencyPackagerType.LAMBDA,
});
new Function(this, 'Function with inline requirements', {
handler: 'index.handler',
code: lambda.Code.fromInline('def handler(event, context):\n import requests'),
runtime: lambda.Runtime.PYTHON_3_9,
// this will create a layer from with requests and Scrapy in a Lambda function instead of locally
layers: [packager.layerFromInline('inline requirements', ['requests', 'Scrapy'])],
});
new Function(this, 'Function with external source and requirements', {
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda-src'),
runtime: lambda.Runtime.PYTHON_3_9,
// this will read pyproject.toml and poetry.lock and create a layer from the requirements in a Lambda function instead of locally
layers: [packager.layerFromPoetry('poetry requirements', 'lambda-src')],
});
Older Implementations
- lovage: standalone Python framework that uses the same trick to deploy decorated functions to AWS
- serverless-pydeps: plugin for Serverless Framework that speeds up deployment
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cloudsnorkel.cdk-turbo-layers-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5f918c1bd58f7089e19232a006af19843c8af437d8d910b864502c810e60bd5 |
|
MD5 | 82bab39e5d3f7ec231759998a8b4cf4a |
|
BLAKE2b-256 | 7bc394d68492a46101f73fe6149e3b47ad7c81284d07d57c5660513eff98830c |
Hashes for cloudsnorkel.cdk_turbo_layers-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af935abbc8fc4c42ed51b5769e04438a3a72f35d062f87101a8c9c3b649fc8a5 |
|
MD5 | 8673f1ec62840e782690accdf31bddb9 |
|
BLAKE2b-256 | e439244cd9e0e3623c59ae224893b5eb845f9cbca46740e42f0c4fa0977fcdcd |