■ はじめに
https://dk521123.hatenablog.com/entry/2017/04/01/235355
https://dk521123.hatenablog.com/entry/2019/12/06/232617
の続き。 Amazon S3 の AWS CLI (aws s3) の存在はしていたが aws s3api の存在を知ったので、メモ。
目次
【1】aws s3api 【2】aws s3 との違い 1)公式ドキュメント 【3】API仕様 1)get-object 2)list-objects-v2 補足1:ETag
【1】aws s3api
* Amazon S3をCLIベースで操作可能
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-services-s3-apicommands.html
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-services-s3-lifecycle-example.html
【2】aws s3 との違い
* aws s3api ... 低レベル (細かいところとかパフォーマンスとか改善できる) * aws s3 ... 高レベル(sync など便利なAPIが揃っている)
aws s3
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-services-s3-commands.html
1)公式ドキュメント
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-services-s3-apicommands.html
より抜粋 ~~~~~ API レベルのコマンド (s3api コマンドセットに含まれる) は、 Amazon Simple Storage Service (Amazon S3) API への直接アクセスを提供し、 高レベルの s3 コマンドでは公開されていない一部の操作を有効にします。 ~~~~~
【3】API仕様
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/index.html
1)get-object
* ファイル取得
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-object.html
aws s3api get-object \ --bucket "$bucket_name" \ --key "$object_name" \ "$destination_file_name"
Options
* --if-match <ETag> ... ETagが一致していたら場合、取得 (それ以外は、エラー「412 Precondition Failed」) * --if-none-match <ETag> ... ETagが異なっていた場合、取得 (それ以外は、エラー「304 Not Modified」)
2)list-objects-v2
* ファイル一覧
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/list-objects-v2.html
aws s3api list-objects-v2 --bucket your-s3-bucket
Output
{ "Contents": [ { "LastModified": "2019-11-05T23:11:50.000Z", "ETag": "\"621503c373607d548b37cff8778d992c\"", "StorageClass": "STANDARD", "Key": "doc1.rtf", "Size": 391 }, { "LastModified": "2019-11-05T23:11:50.000Z", "ETag": "\"d1852dd683f404306569471af106988e\"", "StorageClass": "STANDARD", "Key": "doc4.rtf", "Size": 6225 } ] }
補足1:ETag
* エンティティタグ * HTTP のレスポンスヘッダーで、リソースの特定バージョンの識別子
目的
* キャッシュがより効率的になり通信帯域を節約することができる * リソースが同時に更新されて互いを上書きすることを防ぐ
参考文献
https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/ETag
参考文献
https://dev.classmethod.jp/articles/cli-command-s3-s3-and-s3api-i-tried-to-find-out-what-i-can-do/
関連記事
Amazon S3 ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2017/03/06/212734
Amazon S3 ~ AWS CLI ~
https://dk521123.hatenablog.com/entry/2017/04/01/235355
Amazon S3 ~ AWS CLI / aws s3 ls ~
https://dk521123.hatenablog.com/entry/2024/10/07/152215
Amazon S3 ~ AWS CLI / aws s3 sync ~
https://dk521123.hatenablog.com/entry/2024/06/06/203209
Amazon S3 ~ Boto3編 ~
https://dk521123.hatenablog.com/entry/2019/10/21/230004
Amazon S3 ~ Boto3でファイル存在チェック ~
https://dk521123.hatenablog.com/entry/2022/02/26/182526
boto3 API / list_objects_v2 の 使用上の注意 と その対策
https://dk521123.hatenablog.com/entry/2019/12/06/232617
curl コマンド
https://dk521123.hatenablog.com/entry/2017/12/05/233100