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