Package: cloudsnorkel.cdk-turbo-layers
Turbo Layers for CDKSpeed 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 deployingSupported Lambda runtimes:🐍 Python📜 Node.js💎 Ruby☕ JavaBenchmarkBelow are synth and deploy times for a simple Python function withPythonFunctioncompared to Turbo Layers. Thebenchmarkran three times and the best time were taken for each step.💤 PythonFunction🚀 Turbo Layers💤 5x PythonFunction🚀 5x Functions w/ Shared Turbo LayerInitial Synth1:210:062:430:06Initial Deploy1:182:052:102:06Code Change Synth0:310:061:210:06Code Change Deploy0:490:291:190:36New Dependency Synth0:330:061:300:06New Dependency Deploy0:521:501:311:50As 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 benchmarkAPIThe best way to browse API documentation is onConstructs Hub. It is available in all supported programming languages.InstallationConfirm you're using CDK v2Install the appropriate packagePythonpip install cloudsnorkel.cdk-turbo-layersTypeScript or JavaScriptnpm i @cloudsnorkel/cdk-turbo-layersJava<dependency><groupId>com.cloudsnorkel</groupId><artifactId>cdk.turbo-layers</artifactId></dependency>Gogo get github.com/CloudSnorkel/cdk-turbo-layers-go/cloudsnorkelcdkturbolayers.NETdotnet add package CloudSnorkel.Cdk.TurboLayersExamplesThe very basic example below will create a layer with dependencies specified as parameters and attach it to a Lambda function.constpackager=newPythonDependencyPackager(this,'Packager',{runtime:lambda.Runtime.PYTHON_3_9,type:DependencyPackagerType.LAMBDA,});newFunction(this,'Function with inline requirements',{handler:'index.handler',code:lambda.Code.fromInline('def handler(event, context):\nimport requests'),runtime:lambda.Runtime.PYTHON_3_9,//thiswillcreatealayerfromwithrequestsandScrapyinaLambdafunctioninsteadoflocallylayers:[packager.layerFromInline('inline requirements',['requests','Scrapy'])],});The next example will create a layer with dependencies specified in arequirements.txtfile and attach it to a Lambda function.constpackager=newPythonDependencyPackager(this,'Packager',{runtime:lambda.Runtime.PYTHON_3_9,type:DependencyPackagerType.LAMBDA,});newFunction(this,'Function with external source and requirements',{handler:'index.handler',code:lambda.Code.fromAsset('lambda-src'),runtime:lambda.Runtime.PYTHON_3_9,//thiswillreadrequirements.txtandcreatealayerfromtherequirementsinaLambdafunctioninsteadoflocallylayers:[packager.layerFromRequirementsTxt('requirements.txt','lambda-src')],});Custom package managers like Pipenv or Poetry are also supported.constpackager=newPythonDependencyPackager(this,'Packager',{runtime:lambda.Runtime.PYTHON_3_9,type:DependencyPackagerType.LAMBDA,});newFunction(this,'Function with external source and requirements',{handler:'index.handler',code:lambda.Code.fromAsset('lambda-poetry-src'),runtime:lambda.Runtime.PYTHON_3_9,//thiswillreadpyproject.tomlandpoetry.lockandcreatealayerfromtherequirementsinaLambdafunctioninsteadoflocallylayers:[packager.layerFromPoetry('poetry dependencies','lambda-poetry-src')],});If your dependencies have some C library dependencies, you may need to use the more capable but slower CodeBuild packager.constpackager=newPythonDependencyPackager(this,'Packager',{runtime:lambda.Runtime.PYTHON_3_9,type:DependencyPackagerType.CODEBUILD,preinstallCommands:['apt install -y libxml2-dev libxslt-dev libffi-dev libssl-dev',],});newFunction(this,'Function with external source and requirements',{handler:'index.handler',code:lambda.Code.fromAsset('lambda-pipenv-src'),runtime:lambda.Runtime.PYTHON_3_9,layers:[packager.layerFromPipenv('pipenv dependencies','lambda-pipenv-src')],});Building layers for ARM64 functions is also supported.constpackager=newPythonDependencyPackager(this,'Packager',{runtime:lambda.Runtime.PYTHON_3_9,type:DependencyPackagerType.LAMBDA,architecture:Architecture.ARM_64,});newFunction(this,'Function with external source and requirements',{handler:'index.handler',code:lambda.Code.fromAsset('lambda-poetry-src'),runtime:lambda.Runtime.PYTHON_3_9,architecture:Architecture.ARM_64,layers:[packager.layerFromPoetry('poetry dependencies','lambda-poetry-src')],});All these examples are for Python, but the same API is available for Node.js, Ruby, and Java. The same build options are available. Multiple different package managers are supported. SeeConstructs Hubfor more details.Older Implementationslovage: standalone Python framework that uses the same trick to deploy decorated functions to AWSserverless-pydeps: plugin forServerless Frameworkthat speeds up deployment