Where is documentation on exactly what format of contents of a ZIP file that AWS Lambda supports for Java deployments?
Sure, I’ve read Deploy Java Lambda functions with .zip or JAR file archives and a dozen other similar pages. But they all just say "use Maven Shade Plugin" or "use this setting on Gradle". This doesn’t tell me specifications on the actual content recognized and accepted by AWS Lambda. (For example, AWS Lambda doesn’t support multirelease JARs. Where is that documented?)
Maybe I want to use another approach than Maven Shade Plugin to create my ZIP/JAR files for AWS Lambda. Does AWS Lambda support a directory with library JARs in addition to classes? Does it only support a package-hierarchy of class files? What exactly must go in this ZIP/JAR, and what variations does AWS Lambda support? Where is this documented?
2
Answers
I have verified two layouts accepted by AWS Lambda in practice.
Bare, Unpacked Fat JAR
The first is simply an unpacking of all dependency JARs into the root directory—a "fat JAR" or "uber JAR". This is what the Maven Shade Plugin does, and it has all sorts of downsides. Like Frank Afriat said in his answer, I don't recommend it.
Fat JAR with Lib JARs
A better layout, suggested by Maarten Brak in another answer, is to include only your own project's unpacked class files, but place all the JARs inside a
lib/
subdirectory. This doesn't have the downsides of the Maven Shade Plugin (such as dueling files with the same name and the dilemma of whether to merge them or delete them or move them; and what to do with multirelease JARs). It looks like this:com/
com/example/
com/example/Foo.class
lib/
lib/foo.jar
lib/bar.jar
To generate a JAR file like this, you can use the Maven Assembly Descriptor at the answer I mentioned, or use the Spring Boot Plugin if one day they address Issue #36101 which I filed today.
Note that this answer is provided just to be helpful and it is based upon my research and testing. It is not official documentation. AWS should provide official documentation. If someone finds official documentation and provides an answer saying as much, I'll mark that answer as correct. Thanks!
I discourage you of using the Shade Plugin.
See my post on medium : https://medium.com/@frank-afriat/the-only-good-but-little-known-way-to-package-your-java-lambda-db82f45d8d5d
where I recommend using this in your maven project:
The lambda bundle will appear in your target folder after calling:
mvn package
Regarding the structure of the lambda bundle, the dependencies will go inside a lib folder in the archive.
I suggest you to try my framework https://microlam.io for ease of use and to get a working example.