【AWS CLI 示例集】S3

S3

我们主要检查是否可以使用AWS Cloud9执行命令。
如果您想提供示例命令,请使用下面的表格提交。
如果列出的命令示例有任何错误,请在此处更正。

建议
建议内容可能会被修改。在提出任何建议之前请注意这一点。


查看 S3 存储桶列表

aws s3 ls

输出

2023-02-01 04:54:53 cf-templates-tropical6srv-ap-northeast-1
2023-03-01 03:04:04 cf-templates-tropical6srv-ap-northeast-2
2023-01-01 08:05:31 cf-templates-tropical6srv-us-east-1
2023-01-01 08:18:27 cf-templates-tropical6srv-us-east-2

by anonymous

查看 S3 存储桶的内容

aws s3 ls s3://cf-templates-tropical6srv-ap-northeast-1/

输出

                           PRE .config/
2023-02-01 04:54:53         18 .bash_logout
2023-02-01 04:54:53        193 .bash_profile
2023-02-01 04:54:53        314 .bashrc
2023-02-01 04:54:53         20 .lesshst
2023-02-01 04:54:53        299 .zprofile
2023-02-01 04:54:53       1162 2023-02-01T045453.example.yaml

by anonymous

如果 S3 存储桶为空,则删除

aws s3 rb s3://cf-templates-tropical6srv-ap-northeast-1

输出

remove_bucket failed: s3://cf-templates-tropical6srv-ap-northeast-1 An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty

by anonymous

删除 S3 存储桶,即使它不为空

aws s3 rb s3://cf-templates-tropical6srv-ap-northeast-1 --force

输出

delete: s3://cf-templates-tropical6srv-ap-northeast-1/.bash_logout
delete: s3://cf-templates-tropical6srv-ap-northeast-1/.bash_profile
delete: s3://cf-templates-tropical6srv-ap-northeast-1/.lesshst
delete: s3://cf-templates-tropical6srv-ap-northeast-1/.bashrc
delete: s3://cf-templates-tropical6srv-ap-northeast-1/.zprofile
delete: s3://cf-templates-tropical6srv-ap-northeast-1/2023-02-01T045453.example.yaml
remove_bucket: cf-templates-tropical6srv-ap-northeast-1

by anonymous

删除以特定字符串命名的 S3 存储桶

s3list=$(aws s3 ls | awk '{print $3}' | grep 'cf-')
for i in $s3list; do aws s3 rb s3://$i --force; done

输出

delete: s3://cf-templates-tropical6srv-ap-northeast-2/.bash_logout
delete: s3://cf-templates-tropical6srv-ap-northeast-2/.bash_profile
delete: s3://cf-templates-tropical6srv-ap-northeast-2/.lesshst
delete: s3://cf-templates-tropical6srv-ap-northeast-2/.bashrc
delete: s3://cf-templates-tropical6srv-ap-northeast-2/.zprofile
remove_bucket: cf-templates-tropical6srv-ap-northeast-2
remove_bucket: cf-templates-tropical6srv-us-east-1
remove_bucket: cf-templates-tropical6srv-us-east-2

by anonymous


批量将 S3 存储桶中特定文件夹中的对象下载到本地 (./)

aws s3 cp s3://example_bucket/folder/ ./ \
--recursive

输出

download: s3://example_bucket/folder/subfolder/file1.txt to subfolder/file1.txt
download: s3://example_bucket/folder/subfolder/file2.txt to subfolder/file2.txt
download: s3://example_bucket/folder/subfolder/file3.txt to subfolder/file3.txt
<以下省略>

by anonymous

仅批量下载 S3 存储桶中特定文件夹中特定文件格式 (.csv) 的对象到本地 (./)

aws s3 cp s3://example_bucket/folder/ ./ \
--exclude "*" --include "*.csv" --recursive

输出

download: s3://example_bucket/folder/subfolder/file1.csv to subfolder/file1.csv
download: s3://example_bucket/folder/subfolder/sub/file2.csv to subfolder/sub/file2.csv
download: s3://example_bucket/folder/subfolder/sub/file3.csv to subfolder/sub/file3.csv
<以下省略>

by anonymous

タイトルとURLをコピーしました