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をコピーしました