This post describes a "recipe" for building a deployment package for an Amazon AWS Lambda function authored in Java. The current AWS Lambda documentation (links below in the "references" section) suggest using the "shade" plugin with Maven, which produces an "uber-jar", or using Gradle to produce a zip file containing classes and a "lib" subdirectory with dependency jars. Neither of those approaches is ideal. "Uber-jars" cause problems with any code that uses reflection, and using Gradle seems to assume you've completely set Maven aside as a build tool. This "recipe" assumes you want to use Maven, but you'd still like the zip-containing-jars style deployment package instead of an "uber-jar."
Use Maven's Assembly Plugin
This should be at least a good 90%+ head start on configuring Maven to produce an AWS Lambda deployment package with the dependency libraries still in their original jars and your AWS Lambda function code included in package-directory / class-file format.
Create Assmembly DescriptorWithin the Maven project directory structure, create a file named:
...containing the following content...
Add Plugin Configuration to pom.xml
Note: If this is a multi-module project, with each module producing its own AWS Lambda function deployment package (.zip), then this goes in the sub-module's pom.xml, not the parent. If you have a lot of AWS Lambda function sub-modules, it might be worth trying to use pluginManagement in the parent pom, but that's outside the scope of this post.
<!-- Note: Normally, this plugin would be run using
"mvn compile assembly:single" but the execution
clause below binds it to the normal 'package' lifecycle phase