Manual Deployment
You can deploy your function to AWS Lambda manually by building and uploading an executable JAR file. Various build plugins offer this capability.
Gradle Shadow plugin
The Gradle Shadow plugin provides a shadowJar
task to generate a self-contained executable JAR file, which is suitable for AWS Lambda deployments.
Example build.gradle
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" } (1)
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.4"
...
}
}
apply plugin:"com.github.johnrengelman.shadow"
shadowJar {
mergeServiceFiles()
}
1 | The Gradle Shadow plugin is hosted in the http://plugins.gradle.org repository |
The executable JAR file can now be built using the shadowJar
task.
$ ./gradlew shadowJar
Maven Shade plugin
The Maven Shade plugin will generate an executable JAR file for Maven projects. For further details, consult the AWS Lambda Documentation.
Example pom.xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${exec.mainClass}</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The executable JAR file can now be built using the package
phase.
$ ./mvnw package