The only good but little-known way to package your Java Lambda
--
A few years ago, I tried to develop a Java Lambda with my favorite build tool : maven
I found this on AWS documentation:
AWS is recommending the Shade plugin ???? Seriously ?
My response as a 10+ years Enterprise Java developer : NEVER
Why ? Imagine what the shared plugin is doing: extracting all your dependencies on the same folder… any resource that overlap ? No problem ? Seriously ? And regarding security and jar fingerprint ? No problem also ? And build repeatability ? No problem also ?
You understand why no Java Enterprise developer with some experience will allow that, nor any devops/gitops should allow that…
But this is the recommended way to do it according to AWS? I don’t care, finally when a problem will occur, and you know it will occur according to Murphy’s Law: “Anything that can go wrong will go wrong.” And you will stay alone, with a tricky problem, and AWS will not help you…
So how ? After some reverse engineering, I don’t remember exactly how, it was several years ago, I found that a supported way of doing it was simply to put your dependencies into a zip inside a lib folder ! easy…
Unfortunately, certainly by simplicity, for small hello world project, I found that even experienced developers are still using today the shared plugin... That is one of the reasons of my post: eradicate this bad practice for good.
At first, I was using the assembly plugin with an external descriptor file, today I am the creator of the Microlam project, with one simple goal: make it easy for any Java developer to develop for AWS Serverless so I needed to find an even easier way:
So you just have to copy/paste this piece of code in your pom.xml and you are done with this simple command :
mvn package
You will find a new file in your target folder with a name ending with the suffix -aws-lambda.zip
Hope it will be useful for you.
In case you think about compiling your Java Lambda to Native, I recommend you to try the Microlam micro-framework and why not, to join our beginning new community…