S3

We mainly check whether commands can be executed using AWS Cloud9.
If you would like to provide example commands, please submit them using the form below.
Please also provide corrections if the command examples have mistake.

Suggest
The proposed content may be modified. Please be aware of this before making any suggestions.


List S3 buckets

aws s3 ls

output

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

Show contents of S3 bucket

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

output

                           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

Delete S3 bucket if empty

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

output

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

Delete S3 bucket even if not empty

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

output

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

Delete S3 bucket with name that has a specific string

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

output

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


Download objects in a specific folder in an S3 bucket locally (./) in bulk

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

output

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

Download only objects of a specific file format (.csv) in a specific folder in an S3 bucket locally (./) in bulk

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

output

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