Use Lambda layers to package code and dependencies that you want to reuse across multiple functions. Layers usually contain library dependencies, a custom runtime, or configuration files. Creating a layer involves
three general steps:
Package your layer content. This means creating a .zip file archive that contains the dependencies
you want to use in your functions.
To create a layer, bundle your packages into a .zip file archive that meets the following requirements:
Ensure that the Java version that Maven or Gradle refers to is the same as the Java version of the function that you intend to deploy. For example, for a Java 25 function, the mvn -v command should list Java 25 in the output.
Your dependencies must be stored in the java/lib directory, at the root of the .zip file. For more information, see Layer paths for each Lambda runtime.
The packages in your layer must be compatible with Linux. Lambda functions run on Amazon Linux.
You can create layers that contain either third-party Java libraries or your own Java modules and packages. The following procedure uses Maven. You can also use Gradle to package your layer content.
To create a layer using Maven dependencies
Create an Apache Maven project with a pom.xml file that defines your dependencies.
The following example includes Jackson Databind for JSON processing. The section uses the maven-dependency-plugin to create separate JAR files for each dependency instead of bundling them into a single uber-jar. If you want to create an uber-jar, use the maven-shade-plugin.
Make sure your .zip file includes the java directory at the root level with lib inside it. This structure ensures that Lambda can locate and import your libraries. Each dependency is kept as a separate JAR file rather than bundled into an uber-jar.
Create the layer in Lambda
You can publish your layer using either the AWS CLI or the Lambda console.
Choose Upload a .zip file, and then upload the .zip archive that you created earlier.
(Optional) For Compatible runtimes, choose the Java runtime that corresponds to the Java version you used to build your layer.
Choose Create.
Add the layer to your function
AWS CLI
To attach the layer to your function, run the update-function-configuration AWS CLI command. For the --layers parameter, use the layer ARN. The ARN must specify the version (for example, arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1). For more information, see Layers and layer versions.
The cli-binary-format option is required if you're using AWS CLI version 2. To make this the default setting, run aws configure set cli-binary-format raw-in-base64-out. For more information, see AWS CLI supported global command line options in the AWS Command Line Interface User Guide for Version 2.