AWS CLI cpコマンドでローカルファイルをバケットにコピーする方法

環境
AWS CLI
AWS S3

操作例
1.ローカルファイルをバケットにコピーする
$ ls
test1.csv test1.md test1.txt
$

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws s3 cp test1.txt s3://ark-test-bucket
upload: ./test1.txt to s3://ark-test-bucket/test1.txt
$
$ aws s3 ls s3://ark-test-bucket
2023-03-29 08:29:29 0 test1.txt
$
$ ls
test1.csv test1.md test1.txt
$ aws s3 cp test1.txt s3://ark-test-bucket upload: ./test1.txt to s3://ark-test-bucket/test1.txt $ $ aws s3 ls s3://ark-test-bucket 2023-03-29 08:29:29 0 test1.txt $ $ ls test1.csv test1.md test1.txt
$ aws s3 cp test1.txt s3://ark-test-bucket
upload: ./test1.txt to s3://ark-test-bucket/test1.txt
$
$ aws s3 ls s3://ark-test-bucket
2023-03-29 08:29:29 0 test1.txt
$
$ ls
test1.csv test1.md test1.txt

説明
ローカルファイルをバケットにアップロードできました。
ローカルファイルは残ったままです。

2.オブジェクトをダウンロード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws s3 ls s3://ark-test-bucket/ --recursive
2023-03-29 13:37:16 0 dir/test1.md
2023-03-29 13:37:16 0 test1.csv
2023-03-29 13:37:16 0 test1.txt
$ aws s3 ls s3://ark-test-bucket/ --recursive 2023-03-29 13:37:16 0 dir/test1.md 2023-03-29 13:37:16 0 test1.csv 2023-03-29 13:37:16 0 test1.txt
$ aws s3 ls s3://ark-test-bucket/ --recursive
2023-03-29 13:37:16 0 dir/test1.md
2023-03-29 13:37:16 0 test1.csv
2023-03-29 13:37:16 0 test1.txt

$
$ ls

バケットにオブジェクトが存在して、ローカルには何もない状態です。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws s3 cp s3://ark-test-bucket/ . --recursive
download: s3://ark-test-bucket/test1.csv to ./test1.csv
download: s3://ark-test-bucket/test1.txt to ./test1.txt
download: s3://ark-test-bucket/dir/test1.md to dir/test1.md
$ aws s3 cp s3://ark-test-bucket/ . --recursive download: s3://ark-test-bucket/test1.csv to ./test1.csv download: s3://ark-test-bucket/test1.txt to ./test1.txt download: s3://ark-test-bucket/dir/test1.md to dir/test1.md
$ aws s3 cp s3://ark-test-bucket/ . --recursive
download: s3://ark-test-bucket/test1.csv to ./test1.csv
download: s3://ark-test-bucket/test1.txt to ./test1.txt
download: s3://ark-test-bucket/dir/test1.md to dir/test1.md

バケットのオブジェクトをダウンロードできました。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws s3 ls s3://ark-test-bucket/ --recursive
2023-03-29 13:37:16 0 dir/test1.md
2023-03-29 13:37:16 0 test1.csv
2023-03-29 13:37:16 0 test1.txt
$ aws s3 ls s3://ark-test-bucket/ --recursive 2023-03-29 13:37:16 0 dir/test1.md 2023-03-29 13:37:16 0 test1.csv 2023-03-29 13:37:16 0 test1.txt
$ aws s3 ls s3://ark-test-bucket/ --recursive
2023-03-29 13:37:16 0 dir/test1.md
2023-03-29 13:37:16 0 test1.csv
2023-03-29 13:37:16 0 test1.txt

$
$ ls
dir test1.csv test1.txt

AWS

Posted by arkgame