Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the optimal way to deploy Java AWS Lambda?

There are two approaches of "deploying" a Java Lambda:

  • create a "fat" jar including all (unpackaged) dependencies, e.g. by use of the maven-shade-plugin
  • create a zip file containing my code and a lib directory with all dependencies as jar files

As it takes really long until the environment that executes our simple Lambda is "booted" (20-30s), I wonder if either approach is "faster" than the other or can be further speed up?

like image 619
skirsch Avatar asked Oct 20 '15 18:10

skirsch


People also ask

Is Java good for AWS Lambda?

You can run Java code in AWS Lambda. Lambda provides runtimes for Java that run your code to process events. Your code runs in an Amazon Linux environment that includes AWS credentials from an AWS Identity and Access Management (IAM) role that you manage. Lambda supports the following Java runtimes.

What are the three different ways you can deploy your code to Lambda?

To deploy your function's code, you upload the deployment package from Amazon Simple Storage Service (Amazon S3) or your local machine. You can upload a . zip file as your deployment package using the Lambda console, AWS Command Line Interface (AWS CLI), or to an Amazon Simple Storage Service (Amazon S3) bucket.


1 Answers

I have found that the FAT jar is the optimal approach for lambdas with a footprint smaller than the MB limit. If you are over the MB limit, add the libraries to the lambda's lib folder and read them in.

With jars in the lib, I have found is that the lambda loads a little slower when it launches the first time in a container... the first time it is slower, subsequent launches in the same container are very fast... if it goes to a new container, one-time slow again.

Here is some good info on those cold starts: https://hackernoon.com/im-afraid-you-re-thinking-about-aws-lambda-cold-starts-all-wrong-7d907f278a4f

like image 134
Matt Avatar answered Nov 14 '22 22:11

Matt