2024-03-19
Minio WebUI

Using S3 libraries with Minio mock server

https://sylvainleroy.com/wp-admin/options-general.php?page=ad-inserter.php#tab-2

In the continuation of my previous S3 article,

I present you, how to write an S3 Java Sample program that is using a S3 server to develop the functionalities.

In this article, I will be using :

First step: running our S3 server

We will use Minio as our S3 server.

You need to have Docker installed on your machine. Once Docker is installed. type the following commands in your terminal :

docker pull minio/minio
docker run -p 9000:9000 minio/minio server /data

 

Your terminal should show you something similar to this screenshot :

Minio launching using Docker
Minio launching using Docker

The following information are important :

  • Your access key
  • Your secret token
  • And the endpoint

With your browser, you can open a UI on Minio and browse your buckets and objects :

I modified my Java example to pass all the information’s (link) :


public class AmazonS3Example {

    private static final Logger LOGGER = LoggerFactory.getLogger(AmazonS3Example.class);

    public static void main(final String[] args) {

	final AmazonArgs amazonArgs = new AmazonArgs();
	JCommander.newBuilder().addObject(amazonArgs).build().parse(args);

	amazonArgs.setAccessKey("N386RDH9QVMS0R6XFSJX");
	amazonArgs.setSecretKey("V17KJd7wr0tTxBzhut3ZRTgtRSNf15UjNy1oEcpK");
	amazonArgs.setEndpointURL("http://172.17.0.2:9000");
	amazonArgs.setRegion("us-east-2");
...
}
}

My code is doing these basic tasks :

  • Creating a bucket
  • Get the list of buckets on the server
  • Checking for the existence of this newly created bucket
  • Creating a folder inside this bucket
  • Uploading a file in the folder of this bucket (creates a new object)
  • Reading the object content
  • Deleting the folder
  • Deleting the bucket

Feedback: When writing my example, I had some issues with the client (especially the v2 methods to detect the presence of an object, a cluster) and with the RegionName of the Amazon client that is guessing the region based on the source endpoint. You should rather store this information as a configuration, accessible by all your objects.

Using Minio and an S3 code seems to be easy, for most of the S3 basic operations.

Have you tried it? What is your opinion about Minio?

 

Sylvain Leroy

Senior Software Quality Manager and Solution Architect in Switzerland, I have previously created my own company, Tocea, in Software Quality Assurance. Now I am offering my knowledge and services in a small IT Consulting company : Byoskill and a website www.byoskill.com Currently living in Lausanne (CH)

View all posts by Sylvain Leroy →