Concurrency behavior AWS Lambda

Suppose I have code like this.

public class MyHandler {
    private Foo foo;
    public void handler(InputStream request, OutputStream response, Context context) {
       ...
    }
}

      

Foo foo takes care of creating merged database connections.

I am trying to understand how this works with AWS Lambda. If I understand correctly, foo is shared across multiple calls. The first one takes longer because it has to be loaded into the container, while the later ones are faster because foo is already initialized. This will be the case until my handler is released after a period of inactivity.

So, for sequential calls, will it use the same object, will it have access to the / tmp created by the earlier call to the function?

How about parallel calls? Will it duplicate the entire container, since according to the docs, each lambda function should execute in its own container, its own resources, and its own / tmp?

If the handler crashes after being idle, is there a callback function in Java that I can call to close all open pooled connections?

+3


source to share


1 answer


So, for sequential calls, will it use the same object, does it matter if you have access to the / tmp created by the earlier function call?

Yes, it will use the same object. Yes, it will have access to the /tmp

function created by the earlier call.

How about parallel calls? Will it duplicate the entire container, because according to the docs, each lambda function must execute in its own container, its own resources, and its own / tmp?



Concurrent calls will occur in separate containers. One container only handles one call at a time. So yes, the entire container will be duplicated and each container has its own /tmp

.

If the handler is released after being idle, is there a callback function in Java that I can call to close all open pooled connections?

There is no callback you can use to handle this. Your function will be in a pending state when the container is removed due to inactivity.

+1


source







All Articles