A collection of Maven assembly descriptors for building AWS Lambda deployment packages.
The lambda-zip
descriptor supports building .zip
deployment packages as described in the AWS documentation page, "Creating a ZIP Deployment Package for a Java Function". The resulting .zip
file contains compiled class files and resources at the top level, and all of the required dependencies as .jar
files in the lib/
directory.
This method of packaging Lambda deployment packages has two major advantages over the uberjar
method:
- Reduces the amount of time it takes the Lambda runtime to unpack the deployment package (see the AWS Lambda "Best Practices" page).
- Avoids overlaying unpacked dependencies on top of each other, which leads to resource merge conflicts.
- For Lambda functions that have no dependencies other than
aws-lambda-java-core
. - In cases where classes need to be relocated - use the
maven-shade-plugin
instead.
Add the following plugin configuration to your pom.xml
file:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<dependencies>
<dependency>
<groupId>io.symphonia</groupId>
<artifactId>lambda-packaging</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>lambda-zip</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<finalName>lambda</finalName>
</configuration>
</plugin>
...
</plugins>
...
</build>
With this configuration in place, running mvn package
will produce a lambda.zip
deployment package in the target/
directory.