ablog

不器用で落着きのない技術者のメモ

Amazon S3 のプレフィックスはオブジェクトか?

$ dd if=/dev/urandom of=origin.dat count=100 bs=1M
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.568612 s, 184 MB/s
$ aws s3 mb s3://ponkotsu-jp
make_bucket: ponkotsu-jp
$ aws s3api put-object --bucket ponkotsu-jp --key 2017/ ★ 2017 はプレフィックスだけ先に作成
{
    "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\""
}
$ aws s3 cp origin.dat s3://ponkotsu-jp/2017/AZ
upload: ./origin.dat to s3://ponkotsu-jp/2017/AZ
$ aws s3 cp origin.dat s3://ponkotsu-jp/2017/Horiba
upload: ./origin.dat to s3://ponkotsu-jp/2017/Horiba
$ aws s3 cp origin.dat s3://ponkotsu-jp/2018/FujitaV ★ 2018 はオブジェクト作成時にプレフィックスをつける
upload: ./origin.dat to s3://ponkotsu-jp/2018/FujitaV
$ aws s3 ls --recursive s3://ponkotsu-jp/
2020-05-26 13:18:49          0 2017/ ★2017 は単体でオブジェクトとして存在する
2020-05-26 13:19:29  104857600 2017/AZ
2020-05-26 13:19:48  104857600 2017/Horiba
2020-05-26 13:20:07  104857600 2018/FujitaV ★2018は単体でオブジェクトとして存在しない

追記

$ aws s3api put-object --bucket ponkotsu-jp --key 2019/ --body origin.dat
{
    "ETag": "\"e37b9bbd310ef9eb352e771cb3764608\""
}
$ aws s3 ls --human-readable --recursive s3://ponkotsu-jp/
2020-05-26 13:18:49    0 Bytes 2017/
2020-05-26 13:19:29  100.0 MiB 2017/AZ
2020-05-26 13:19:48  100.0 MiB 2017/Horiba
2020-05-26 13:20:07  100.0 MiB 2018/FujitaV
2020-05-26 14:38:57  100.0 MiB 2019/ ★100MBのプレフィックスなオブジェクト氏

もうちょっと追記

$ aws s3 rm s3://ponkotsu-jp/2017/AZ
delete: s3://ponkotsu-jp/2017/AZ
$ aws s3 rm s3://ponkotsu-jp/2017/Horiba
delete: s3://ponkotsu-jp/2017/Horiba
$ aws s3 rm s3://ponkotsu-jp/2018/FujitaV
delete: s3://ponkotsu-jp/2018/FujitaV
$ aws s3 ls --human-readable --recursive s3://ponkotsu-jp/
2020-05-26 13:18:49    0 Bytes 2017/
2020-05-26 14:38:57  100.0 MiB 2019/