0
votes

Lambda is supposedly spinning up a contrainer and that container is reused if possible to avoid reconnections (databases etc) and cold start (download zip, unzip it, parse etc).

AWS and many others recommend to set a scheduled event that pokes Lambda function in every X minutes/seconds to keep it warm.


But I cannot find an answer anywhere to that simple question: does that single container somehow gets reused every single time that function is ran?

What if that warm Lambda functions is concurrently ran 500 times? All of those leverage that container or only the first and the rest get a cold start?

1

1 Answers

0
votes

You have no guarantee of container reuse. This is the magic of AWS Lambda. Containers can come and go as needed. For example, your first request may hit a container running in AZ A and your next request may hit a container in AZ B. So, some may get cold starts, some may not, there are a lot of factors at play that you don't have control over. For good reasons, AWS doesn't share the details of their container placement and container re-usability strategies.

You may be able to approach your problem with a bit of a different pattern, though. One example would be to use Lambda to loop over the "queue" of work to do and if you're nearing the timeout (context.getRemainingTimeInMillis()), invoke another instance of your Lambda using the async invocation type.