2

Let's assume I have one AWS lambda Function

**String lambdaFunction1() {
//some processing 
}**

Let's say lambdaFunction1 is triggered on any new message in SNS Topic. How many JVM instances will be triggered for 10 SNS messages?

Does AWS lambda execute each lambda in it's own JVM or it re-utilizes same JVM instances.

7
  • What difference would that make to you? Commented Mar 1, 2018 at 9:16
  • 1. this is to understand how it works 2. it will help in designing connection pool when we access dB Commented Mar 1, 2018 at 9:17
  • The following blog entry gives good insight on how AWS reuses its containers: aws.amazon.com/de/blogs/compute/container-reuse-in-lambda I do not think you can say how many JVM instances are created though and to be honest you also should not be concerned about this. Commented Mar 1, 2018 at 9:18
  • this is to understand how does AWS maintain JVM and secondly it will help in designing DB connection pool in lambda Commented Mar 1, 2018 at 9:19
  • Thanks Ben for your thoughtful answer. Commented Mar 1, 2018 at 9:20

1 Answer 1

2

Quoting https://aws.amazon.com/de/blogs/compute/container-reuse-in-lambda/

Let’s say your function finishes, and some time passes, then you call it again. Lambda may create a new container all over again, in which case the experience is just as described above. This will be the case for certain if you change your code.

However, if you haven’t changed the code and not too much time has gone by, Lambda may reuse the previous container. This offers some performance advantages to both parties: Lambda gets to skip the nodejs language initialization, and you get to skip initialization in your code. Files that you wrote to /tmp last time around will still be there if the sandbox gets reused.

Remember, you can’t depend on a container being reused, since it’s Lambda’s prerogative to create a new one instead.

As said: You can not depend on the container being reused but there is a good chance when AWS deems it a performance gain.

Or to keep it simpler: AWS probably knows what to do to get your Lambdas as efficient as possible so you should not really overthink this probably.

Also while this blog is aimed at Node.js AWS seems to do something similar for Java based on this post by them.

Sign up to request clarification or add additional context in comments.

2 Comments

And on of the key takeaways is that your lambda must not keep state, neither in memory nor on disk since otherwise repeated executions on the same instance will get you into trouble.
Ok, that means each lambda instance is one container. thanks for insight

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.