S3 on premise and edge ?
Amazon S3 (Simple Storage Service) is a cloud storage service provided by Amazon Web Services (AWS). It allows users to store and retrieve data from anywhere on the web.
Minio is an open-source object storage server that implements the same Amazon S3 API as AWS. It can be used to store and retrieve data in the same way as S3, but it can be installed and run on-premises, rather than being a cloud-based service. This allows users to have more control over their data, as it is stored and managed on their own servers rather than being stored and managed by a third-party service.
Minio can also be used on the edge, meaning it can be installed and run on devices at the edge of a network, such as gateways, routers, and IoT devices. This allows for low-latency data storage and retrieval, as the data is stored and processed locally rather than being transmitted over the internet to a remote server.
To get started with Minio:
you will need to install the Minio server on a machine or in a cloud environment. You can download the latest binary version of Minio from the Minio website or install it using docker
In this example we will install it using docker and docker-compose
![](https://abdelouahabmbarki.com/content/images/2022/12/Screenshot-from-2022-12-20-13-27-47.png)
Create a directory for your Minio configuration and create a docker-compose.yml
file in it with the following content:
version: '3'
services:
minio:
image: quay.io/minio/minio:RELEASE.2022-12-12T19-27-27Z
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_ACCESS_KEY: 'your-access-key'
MINIO_SECRET_KEY: 'your-secret-key'
command: server --console-address ":9001" /data
volumes:
- minio_data:/data
volumes:
minio_data:
Replace your-access-key
and your-secret-key
with the access and secret keys that you want to use for Minio. The /data
volume is used to store Minio data.
Run the following command to start Minio using Docker Compose:
docker-compose up
This will download the Minio Docker image and start the Minio server. You can access the Minio web UI by going to http://localhost:9001
iin your web browser this .
Interact with Minio Using CLI:
Minio comes with a command-line interface (CLI) that allows you to manage your object storage from the terminal. To use the Minio CLI, you will need to install it on your machine. You can download the latest version of the Minio CLI from the Minio website
Once you have the Minio CLI installed, you can use it to perform various operations on your Minio server. Here are some basic Minio command line interface (CLI) commands that you can use to manage your Minio server:
mc config host add
: Add a new host to the Minio configuration file.mc ls
: List the objects and directories in a bucket.mc mb
: Create a new bucket.mc cp
: Copy a file from the local filesystem to a bucket, or from a bucket to the local filesystem.mc mirror
: Mirror a directory from the local filesystem to a bucket, or from a bucket to the local filesystem.mc rm
: Remove an object or directory from a bucket.mc policy
: Set or delete bucket policies.mc events
: List events from a bucket.
For example, you can Use the mc alias set
command to add you minio server tomc
configuration.
mc alias set my-minio http://localhost:9000 ACCESS_KEY SECRET_KEY
to create a new bucket called "my-bucket", you can use the following command:
mc mb my-minio/my-bucket
To copy a file called "local-file.txt" from the local filesystem to the "my-bucket" bucket, you can use the following command:
mc cp local-file.txt my-minio/my-bucket
Interact with Minio Using SDKs:
Minio provides several SDKs that allow you to interact with the object storage server from your applications. The SDKs are available in a variety of languages, including Go, Java, Python, and more.
Here is an example of how to use the Minio SDK for Go to connect to a Minio object storage server and perform some basic operations:
package main
import (
"context"
"fmt"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
func main() {
// Create a Minio client
client, err := minio.New("YOUR_MINIO_SERVER_ADDRESS", &minio.Options{
Creds: credentials.NewStaticV4("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", ""),
Secure: true,
})
if err != nil {
fmt.Println(err)
return
}
// Create a new bucket
err = client.MakeBucket(context.Background(), "my-bucket", minio.MakeBucketOptions{Region: "us-east-1"})
if err != nil {
// Check to see if the bucket already exists
exists, err := client.BucketExists(context.Background(), "my-bucket")
if err == nil && exists {
fmt.Println("Bucket already exists")
} else {
fmt.Println(err)
return
}
}
// Upload an object to the bucket
_, err = client.PutObject(context.Background(), "my-bucket", "my-object.txt", strings.NewReader("Hello, Minio!"), -1, minio.PutObjectOptions{ContentType: "text/plain"})
if err != nil {
fmt.Println(err)
return
}
// Download the object from the bucket
object, err := client.GetObject(context.Background(), "my-bucket", "my-object.txt", minio.GetObjectOptions{})
if err != nil {
fmt.Println(err)
return
}
defer object.Close()
// Read the contents of the object
data, err := ioutil.ReadAll(object)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(data))
}
In this example, we create a Minio client and use it to connect to a Minio server. Then, we create a new bucket, upload an object to the bucket, and download the object from the bucket. Finally, we read the contents of the object and print them to the console.
This is just a basic example of how to use the Minio SDK for Go. The Minio SDK provides a wide range of methods and functions that allow you to perform a variety of operations on your Minio server. You can find more information about the available methods and how to use them in the Minio SDK for Go documentation.
Conclusion:
Minio is a powerful and easy-to-use object storage server that is compatible with Amazon S3 APIs. Whether you are a developer looking to store and retrieve data from your applications or a system administrator looking for a scalable and reliable storage solution, Minio is a great choice. With its simple CLI and wide variety of SDKs, Minio makes it easy to manage and access your data.