Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I close an AWS S3 client connection

What is the protocol for closing an aws s3 client connection?

@Override
public boolean connect() {

    if (connected)
        return false;
    else
        s3Client = new AmazonS3Client(credentials);
    return true;
}

@Override
public boolean diconnect() {
    // what should take place here? 
    return false;
}
like image 881
visc Avatar asked Nov 11 '14 14:11

visc


2 Answers

You don't need to close a 'connection", as there's no such thing as a continuous connection to S3 when using AmazonS3Client.

The AWS java SDK send REST requests to S3, where REST is stateless, for each REST request, it will be signed with the user credentials information, so it doesn't need a long connection(such as something like session).

like image 68
Matt Avatar answered Sep 22 '22 16:09

Matt


According to the official documentation:

Service clients in the SDK are thread-safe and, for best performance, you should treat them as long-lived objects. Each client has its own connection pool resource. Explicitly shut down clients when they are no longer needed to avoid resource leaks.

Consider this, if it lives in a service, you're probably fine leaving it open while your app runs. If you create new clients all the time, you should shut them down to avoid memory leaks. In this case, you should run s3Client.shutdown();

like image 33
siRtobey Avatar answered Sep 24 '22 16:09

siRtobey