AWS CLI with MinIO Server

1、Install MinIO Server

https://min.io/docs/minio/linux/index.html

Create AK and SK and record information.

AK:ZYYMPcLi6dSPsDfr5QeW
SK:Am3m2qtpkUk2wAgT5dPbpE4hGD2tX7a6RpjsbeEd

And create a bucket named aswtest.

2、Install AWS CLI

Refer to https://aws.amazon.com/cli/
Testing on Rcoky Linux 9.4

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install

Check

[root@mydb ~]# aws --version
aws-cli/2.19.1 Python/3.12.6 Linux/5.14.0-427.42.1.el9_4.x86_64 exe/x86_64.rocky.9

3、configuration

Fill in AK and SK, region, region default us-east-1, and press enter after format.

[root@mydb ~]# aws configure
AWS Access Key ID [None]: ZYYMPcLi6dSPsDfr5QeW
AWS Secret Access Key [None]: Am3m2qtpkUk2wAgT5dPbpE4hGD2tX7a6RpjsbeEd
Default region name [None]: us-east-1
Default output format [None]:

Additionally enable AWS Signature Version ‘4’ for MinIO server.

[root@mydb ~]# aws configure set default.s3.signature_version s3v4

4、Common commands and scenarios

1.To list your buckets

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 ls
2024-11-02 21:37:27 aswtest

2.To make a bucket

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 mb s3://dbbucket
make_bucket: dbbucket

Check

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 ls
2024-11-02 21:37:27 aswtest
2024-11-02 21:42:40 dbbucket

3.Upload objects to the bucket or download objects from the bucket to the local area.
Use the s3 cp command to copy objects from buckets or local directories.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 cp awscliv2.zip s3://dbbucket
upload: ./awscliv2.zip to s3://dbbucket/awscliv2.zip

Check and list the objects in the bucket.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 ls s3://dbbucket
2024-11-02 21:44:15   66658000 awscliv2.zip

Download object to local

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 cp s3://dbbucket/sysbench-1.0.20.zip /root/dir1/
download: s3://dbbucket/sysbench-1.0.20.zip to dir1/sysbench-1.0.20.zip

Or use synchronization to download all objects.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 sync s3://dbbucket /root/dir1/
download: s3://dbbucket/sysbench-1.0.20.zip to dir1/sysbench-1.0.20.zip

4Delete the object in the bucket.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 rm s3://dbbucket/awscliv2.zip
delete: s3://dbbucket/awscliv2.zip

Check

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 ls s3://dbbucket

5.Delete bucket

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 rb s3://dbbucket
remove_bucket: dbbucket

Check

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 ls
2024-11-02 21:37:27 aswtest

6.Moving object
Use the s3 mv command to move objects from buckets or local directories. This s3 mv command copies the source object or file to the specified destination, and then deletes the source object or file.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 mb s3://dbbucket
make_bucket: dbbucket

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 mv awscliv2.zip s3://dbbucket
move: ./awscliv2.zip to s3://dbbucket/awscliv2.zip

[root@mydb ~]# ls -lsa
total 40
4 dr-xr-x---.  5 root root 4096 Nov  2 21:52 .
0 dr-xr-xr-x. 18 root root  255 Nov  2 15:36 ..
4 -rw-------.  1 root root 1177 Oct 27 14:04 anaconda-ks.cfg
0 drwxr-xr-x   2 root root   39 Nov  2 21:36 .aws
0 drwxr-xr-x   3 root root   78 Nov  1 18:14 aws
4 -rw-------.  1 root root 1047 Nov  2 15:46 .bash_history
4 -rw-r--r--.  1 root root   18 May 11  2022 .bash_logout
4 -rw-r--r--.  1 root root  141 May 11  2022 .bash_profile
4 -rw-r--r--.  1 root root  429 May 11  2022 .bashrc
4 -rw-r--r--.  1 root root  100 May 11  2022 .cshrc
4 -rw-------.  1 root root   20 Oct 27 14:06 .lesshst
0 drwx------.  2 root root    6 Oct 27 13:57 .ssh
4 -rw-r--r--.  1 root root  129 May 11  2022 .tcshrc
4 -rw-------   1 root root  815 Nov  2 21:15 .viminfo

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 ls s3://dbbucket
2024-11-02 21:52:51   66658000 awscliv2.zip

7.aws s3 sync
The s3 sync command synchronizes the contents of a bucket with a directory, or synchronizes the contents of two buckets. Typically, s3 sync copies missing or outdated files or objects between the source and the target. However, you can also provide the --delete option to delete files or objects that do not exist in the source from the target.

You can synchronize local files to the bucket, or you can synchronize the bucket to the local.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 cp sysbench-1.0.20.zip s3://dbbucket
upload: ./sysbench-1.0.20.zip to s3://dbbucket/sysbench-1.0.20.zip
[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 sync /root/dir1 s3://dbbucket
[root@mydb ~]# ls -lsa /root/dir1/
total 4
0 drwxr-xr-x  2 root root    6 Nov  2 22:01 .
4 dr-xr-x---. 6 root root 4096 Nov  2 22:03 ..
[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 sync s3://dbbucket /root/dir1/
download: s3://dbbucket/sysbench-1.0.20.zip to dir1/sysbench-1.0.20.zip

8.Delete all files under the bucket, parameter recursive

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 rm s3://dbbucket --recursive

9.If there are files in the bucket, you need to delete the files before deleting the bucket.

[root@mydb ~]# aws --endpoint-url http://192.168.5.130:9000 s3 rb s3://dbbucket
remove_bucket failed: s3://dbbucket An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty

10.If you don’t want to enter --endpoint-url on the command line.
method
https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-endpoints.html

There is a config file under the. aws file in the root directory. Just add endpoint_url = at the end.

[root@mydb .aws]# pwd
/root/.aws
[root@mydb .aws]# ls -lsa
total 12
0 drwxr-xr-x  2 root root   39 Nov  2 22:19 .
4 dr-xr-x---. 6 root root 4096 Nov  2 22:19 ..
4 -rw-------  1 root root  105 Nov  2 22:19 config
4 -rw-------  1 root root  116 Nov  2 21:36 credentials

[root@mydb .aws]# cat config
[default]
region = us-east-1
s3 =
    signature_version = s3v4
endpoint_url = http://192.168.5.130:9000

Check

[root@mydb .aws]# aws s3 ls
2024-11-02 21:37:27 aswtest
2024-11-02 21:52:46 dbbucket

5、Ref

https://min.io/docs/minio/linux/integrations/aws-cli-with-minio.html
https://docs.aws.amazon.com/zh_cn/cli/v1/userguide/cli-services-s3-commands.html

你可能感兴趣的:(aws,云计算)