0

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?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • Your comments make sense. There can be more theory for sure in this doc topic. I recommend that you go the link named "Provide feedback" located in the 1st link. In the form that opens, specify the points you raised in this thread. This will go to the people responsible for this Doc Set. – smac2020 Jun 27 '23 at 18:39
  • I added feedback to the page in the documentation, but there's no way to track that or even know if someone sees it. – Garret Wilson Jun 28 '23 at 13:35
  • 1
    They see it. AWS has a system that sends it to the correct person. – smac2020 Jun 28 '23 at 13:40

2 Answers2

1

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. If AWS official documentation exists, an answer here on that subject would be welcome.

halfer
  • 19,824
  • 17
  • 99
  • 186
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
0

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:

     <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
                <dependencies>
                  <dependency>
                    <groupId>io.microlam</groupId>
                    <artifactId>microlam-assembly-descriptor</artifactId>
                    <version>1.3</version>
                  </dependency>
                </dependencies>
        
        <configuration>
          <descriptorRefs>
              <descriptorRef>aws-lambda</descriptorRef>
          </descriptorRefs>
        </configuration>
          
            <executions>
            <execution>
                <id>aws-lambda-deployment-package</id>
                <phase>package</phase>
                <goals>
                <goal>single</goal>
                </goals>
            </execution>
            </executions>
    </plugin>

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.

Frank AFRIAT
  • 179
  • 1
  • 6
  • I also would rather not use the Maven Shade Plugin! But the main purpose of this ticket is to get the documentation on what the AWS Lambda ZIP file layout needs to be. It appears that somehow you knew what the layout should be when you created your `io.microlam:microlam-assembly-descriptor`, so if you could share where the documentation is you followed, that would be great. – Garret Wilson Jun 27 '23 at 23:23
  • I was just now discussing on [`MASSEMBLY-992`](https://issues.apache.org/jira/browse/MASSEMBLY-992) the need for the Maven Assembly Plugin to allow in-POM assembly descriptors. It looks like you've already published a Maven Assembly Plugin descriptor for this, `io.microlam:microlam-assembly-descriptor`. I found it [on GitHub](https://github.com/microlam-io/microlam-assembly-descriptor); I'll leave a comment there. – Garret Wilson Jun 27 '23 at 23:27
  • 1
    The structure of the zip has been discovered by reverse engineering with the Lambda plugin for eclipse and with the zip generated by gradle. – Frank AFRIAT Jun 28 '23 at 07:54