

Instead of bundling the SDK with each function deployment, you can create a layer containing the SDK. Once you include this library, your code always uses the version in the deployment package and not the version included in the Lambda service.Ī serverless application may consist of many functions, which all use a common SDK version. You can achieve this by including the SDK with your code package. You can see the current version used by Lambda by declaring an instance of the SDK and logging out the version method:įor production workloads, it’s best practice to lock the version of the AWS SDK used in your functions. As a result, the version may change at any time. The SDK is upgraded frequently to support new AWS services and features. However, there is no guarantee of the version provided in the execution environment. The Lambda service includes the AWS SDK so you can use it without explicitly importing in your deployment package. The AWS SDK allows you to interact programmatically with AWS services using one of the supported runtimes.
AMAZON PERFECT LAYERS ARCHIVE
By moving runtime dependencies from your function code to a layer, this can help reduce the overall size of the archive uploaded during a deployment. Using layers can make it faster to deploy applications with the AWS Serverless Application Model (AWS SAM) or the Serverless framework. Permissions only apply to a single version of a layer. Layers are automatically set as private, but they can be shared with other AWS accounts, or shared publicly. When you include a layer in a function, you specify the layer version you want to use. Layers are deployed as immutable versions, and the version number increments each time you publish a new layer. You can include up to five layers per function, which count towards the standard Lambda deployment size limits.


When you include a layer in a function, the contents are extracted to the /opt directory in the execution environment. Overview of Lambda layersĪ Lambda layer is an archive containing additional code, such as libraries, dependencies, or even custom runtimes. This code in this post is available at this GitHub repo. To learn more, refer to Using serverless backends to iterate quickly on web apps – part 1.
AMAZON PERFECT LAYERS HOW TO
This blog post references the Happy Path application, which shows how to build a flexible backend to a photo-processing web application. In this post, I explain how layers work, and how you can build and include layers in your own applications. While you can zip these dependencies as part of the build and deployment process, in many cases it’s easier to use layers instead. Serverless developers frequently import libraries and dependencies into their AWS Lambda functions.
