user1908568
user1908568

Reputation: 89

Aws lambda functions multiple jars vs single jar

Lets say you have a feature to reserve a dining table broken down into multiple lambda functions ex:

1. RestaurantsLambda - get list of restaurants etc
2. BookingLambda - takes payment, confirms booking etc
3. EmailLambda - sending confirmation emails.

Now will you place all the above lambdas in 1 jar or have jar per lambda?

Upvotes: 1

Views: 806

Answers (1)

Gustavo Tavares
Gustavo Tavares

Reputation: 2805

Probably all the functions are very small. If is the case, in the end of the day it will not make difference. But if they are big or, the functions has different dependencies, it will make difference, but...

The best practice is to keep in the lambda only the code needed by the function. This includes dependencies and libraries, and of course the main code. This best practice is based on the fact that for lambda execution the code must be downloaded at the first invocation (after a while, the code is dismissed and the next invocations will be treated as first again). In Java there is a extra pain that is the process of class loading that happens before code execution.

So: the best way to understand this response is: Bigger the code base, more time needed to load the function and more time that it will cost you.

Long story short: One jar per function!

Extra point: In Java you must be very caution with libraries to be imported. In aws-sdk for example, you must only import the libraries that you'll need instead of import the entire aws-sdk. This will keep your functions slim and ... read again the last paragraph...;-)

Upvotes: 1

Related Questions