How do I close an AWS S3 client connection
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).
In the documentation there is an optional method called 'shutdown'
Shuts down this client object, releasing any resources that might be held open. This is an optional method, and callers are not expected to call it, but can if they want to explicitly release any open resources. Once a client has been shutdown, it should not be used to make any more requests.
For example
@Override
public boolean disconnect() {
s3Client.shutdown()
return false;
}
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();