AWS CLI v2 S3関連を色々試してみる
参考ドキュメント
Command Referenceより、s3とつくサービスは
- s3
- s3api
- s3control
- s3outposts
s3 と s3apiの違いって
公式ドキュメントより
- s3 層は、オブジェクトおよびバケットの作成、操作、削除など、一般的なタスクの実行を簡素化する高レベルコマンドで構成されます。
- s3api 層は、すべての Amazon S3 API オペレーションへの直接アクセスを公開することで、AWS の他のサービスと同様に動作します。これにより、次の層の高レベルコマンドだけでは不可能なアドバンスドオペレーションを実行できるようになります。
s3apiは、APIとコマンドが対応している低レベルコマンド群。
s3は、複数リクエストにまたがる並列アップロードが実装された高レベルコマンド群。
Amazon S3 基礎知識
- バケット:トップレベルのAmzon S3 フォルダ
- プレフィックス:バケット内のAmazon S3 フォルダ
- オブジェクト:Amazon S3 バケットでホストされている全てのアイテム
- ストレージクラス
- ライフサイクル
- オブジェクトロック
- レプリケーション
- バッチ操作
- ブロックパブリックアクセス
- IAMによるアクセス管理
- バケットポリシー
- ACL
- S3 Object Lambda
- イベント通知
実行環境
- AWS CloudShell
- マネジメントコンソールの右上のCloudShellボタンから起動できる
- ログイン中のアカウントの権限で、CloudShellも実行される
AWS CLI バージョンの確認
[cloudshell-user@ip-10-0-78-85 ~]$ aws --version
aws-cli/2.4.6 Python/3.8.8 Linux/4.14.252-195.483.amzn2.x86_64 exec-env/CloudShell exe/x86_64.amzn.2 prompt/off
バケットの作成
マネジメントコンソールからもバケットの作成が確認できた。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 mb s3://yahoooooo-test-bucket
make_bucket: yahoooooo-test-bucket
もう一回、同じコマンド打ってみると、
同じバケットあるから作れませんっていうエラーを吐く。
グローバルで一意なバケットしか作れないという制約がある。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 mb s3://yahoooooo-test-bucket
make_bucket failed: s3://yahoooooo-test-bucket An error occurred (BucketAlreadyOwnedByYou) when calling the CreateBucket operation: Your previous request to create the named bucket succeeded and you already own it.
バケットとオブジェクトの一覧表示
すべてのAmazon S3 バケットの一覧表示
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls
2022-01-11 08:46:58 yahoooooo-test-bucket
バケット内のすべてのオブジェクトとプレフィックスの一覧表示
マネジメントコンソールから作ったテストフォルダとテストオブジェクトが確認できた。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket
PRE test-forder/
2022-01-11 08:55:26 0 test-object.txt
プレフィックスを以下のようにすると、特定の階層で確認ができる。
1行目にはフォルダの情報が表示されている。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket/test-forder/
2022-01-11 08:54:59 0
2022-01-11 08:59:34 0 test-object.txt
オプション
--recursive(再帰的)
再帰的な参照ができる。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket --recursive
2022-01-11 08:54:59 0 test-forder/
2022-01-11 08:59:34 0 test-forder/test-object.txt
2022-01-11 09:02:13 6 test-forder/test-object2.txt
2022-01-11 09:02:11 6 test-forder/test-object3.txt
2022-01-11 08:55:26 0 test-object.txt
--human-readable(人間が読み取れるフォーマット)
--humanに省略可能。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket --recursive --human-readable
2022-01-11 08:54:59 0 Bytes test-forder/
2022-01-11 08:59:34 0 Bytes test-forder/test-object.txt
2022-01-11 09:02:13 6 Bytes test-forder/test-object2.txt
2022-01-11 09:02:11 6 Bytes test-forder/test-object3.txt
2022-01-11 08:55:26 0 Bytes test-object.txt
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket --recursive --human
2022-01-11 08:54:59 0 Bytes test-forder/
2022-01-11 08:59:34 0 Bytes test-forder/test-object.txt
2022-01-11 09:02:13 6 Bytes test-forder/test-object2.txt
2022-01-11 09:02:11 6 Bytes test-forder/test-object3.txt
2022-01-11 08:55:26 0 Bytes test-object.txt
--summarize(要約情報)
--sumに省略可能。
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket --recursive --human --summarize
2022-01-11 08:54:59 0 Bytes test-forder/
2022-01-11 08:59:34 0 Bytes test-forder/test-object.txt
2022-01-11 09:02:13 6 Bytes test-forder/test-object2.txt
2022-01-11 09:02:11 6 Bytes test-forder/test-object3.txt
2022-01-11 08:55:26 0 Bytes test-object.txt
Total Objects: 5
Total Size: 12 Bytes
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls s3://yahoooooo-test-bucket --recursive --human --sum
2022-01-11 08:54:59 0 Bytes test-forder/
2022-01-11 08:59:34 0 Bytes test-forder/test-object.txt
2022-01-11 09:02:13 6 Bytes test-forder/test-object2.txt
2022-01-11 09:02:11 6 Bytes test-forder/test-object3.txt
2022-01-11 08:55:26 0 Bytes test-object.txt
Total Objects: 5
Total Size: 12 Bytes
S3アクセスポイント経由
[cloudshell-user@ip-10-0-78-85 ~]$ aws s3 ls アクセスポイント
PRE test-forder/
2022-01-11 08:55:26 0 test-object.txt
S3アクセスポイントってなにって話は、ここの記事がすごく分かりやすかった。
CloudShellでNanoを使う方法
sudo yum install nano
これでファイルを作成する。
nano test.txt
ローカルファイルをS3にコピーする
[cloudshell-user@ip-10-0-25-218 ~]$ aws s3 cp test.txt s3://yahoooooo-test-bucket
upload: ./test.txt to s3://yahoooooo-test-bucket/test.txt
有効期限付きのローカルファイルをS3にコピーする
[cloudshell-user@ip-10-0-25-218 ~]$ aws s3 cp test.txt s3://yahoooooo-test-bucket/test2.txt --expires 2022-01-11T10:44:00Z
upload: ./test.txt to s3://yahoooooo-test-bucket/test2.txt
有効期限が切れたら、何かアクションが起きるとかそういうことではないみたい。
バケットにライフサイクルを設定することで、規定日数で有効期限を切れさせたり、
その有効期限が切れたら、削除するといったことができる。
有効期限の確認
aws s3
はs3://{バケット名}
だったけど、aws s3api
の bucketオプションは、--bucket {バケット名}
なんだねえ。
[cloudshell-user@ip-10-0-25-218 ~]$ aws s3api head-object --bucket yahoooooo-test-bucket --key test2.txt
{
"AcceptRanges": "bytes",
"LastModified": "2022-01-11T10:43:26+00:00",
"ContentLength": 5,
"ETag": "\"d8e8fca2dc0f896fd7cb4cb0031ba249\"",
"ContentType": "text/plain",
"Expires": "2022-01-11T10:44:00+00:00",
"Metadata": {}
}
S3からS3へのファイルコピー
同一バケット内で、test2.txt を test3.txt としてコピーする。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp s3://yahoooooo-test-bucket/test2.txt s3://yahoooooo-test-bucket/test3.tx
copy: s3://yahoooooo-test-bucket/test2.txt to s3://yahoooooo-test-bucket/test3.txt
同一バケットの別プレフィックスに対して、text3.txtをコピーする。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp s3://yahoooooo-test-bucket/test3.txt s3://yahoooooo-test-bucket/test-forder/test3.txt
copy: s3://yahoooooo-test-bucket/test3.txt to s3://yahoooooo-test-bucket/test-forder/test3.txt
別のバケットに対して、コピーする。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp s3://yaho-test-bucket1/test.txt s3://yaho-test-bucket2/prefix1/test2.txt
copy: s3://yaho-test-bucket1/test.txt to s3://yaho-test-bucket2/prefix1/test2.txt
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 ls s3://yaho-test-bucket2 --recursive
2022-01-12 00:33:03 5 prefix1/test.txt
2022-01-12 00:35:00 5 prefix1/test2.txt
2022-01-12 00:32:10 5 test.txt
S3オブジェクトをローカルに再帰的にコピーする
recursiveオプションって便利ですね。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp s3://yaho-test-bucket2 . --recursive
download: s3://yaho-test-bucket2/test.txt to ./test.txt
download: s3://yaho-test-bucket2/prefix1/test.txt to prefix1/test.txt
download: s3://yaho-test-bucket2/prefix1/test2.txt to prefix1/test2.txt
[cloudshell-user@ip-10-0-3-195 ~]$ ls -R
.:
prefix1 test.txt
./prefix1:
test2.txt test.txt
ローカルファイルをS3に再帰的にコピーする
ホームディレクトリだと、lsコマンドだけでは見えないファイルがあるんだった。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp . s3://yaho-test-bucket3 --recursive
upload: ./.bash_logout to s3://yaho-test-bucket3/.bash_logout
upload: ./.bash_history to s3://yaho-test-bucket3/.bash_history
upload: ./.bash_profile to s3://yaho-test-bucket3/.bash_profile
upload: ./.bashrc to s3://yaho-test-bucket3/.bashrc
upload: .config/powershell/Microsoft.PowerShell_profile.ps1 to s3://yaho-test-bucket3/.config/powershell/Microsoft.PowerShell_profile.ps1
upload: ./test.txt to s3://yaho-test-bucket3/test.txt
upload: prefix1/test.txt to s3://yaho-test-bucket3/prefix1/test.txt
upload: prefix1/test2.txt to s3://yaho-test-bucket3/prefix1/test2.txt
upload: ./.zshrc to s3://yaho-test-bucket3/.zshrc
upload: ./.viminfo to s3://yaho-test-bucket3/.viminfo
upload: ./.swp to s3://yaho-test-bucket3/.swp
s3 rb
コマンドは空のS3バケットを削除するコマンド。
--force
オプションを使えば、バージョン管理されていないオブジェクトに関しては削除される。
バージョン管理されたオブジェクトを削除するには、s3api delete-object
コマンドで--version-id
の指定が必要だそう。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 rb s3://yaho-test-bucket3 --force
delete: s3://yaho-test-bucket3/.bash_history
delete: s3://yaho-test-bucket3/.bash_logout
delete: s3://yaho-test-bucket3/.bash_profile
delete: s3://yaho-test-bucket3/.bashrc
delete: s3://yaho-test-bucket3/prefix1/test.txt
delete: s3://yaho-test-bucket3/.config/powershell/Microsoft.PowerShell_profile.ps1
delete: s3://yaho-test-bucket3/.viminfo
delete: s3://yaho-test-bucket3/prefix1/test2.txt
delete: s3://yaho-test-bucket3/test.txt
delete: s3://yaho-test-bucket3/.zshrc
delete: s3://yaho-test-bucket3/.swp
remove_bucket: yaho-test-bucket3
aws s3 rb
コマンドの挙動1
バージョン管理しているバケットへのマネジメントコンソールから、バケットのバージョニングを有効にして、
test.txtを2回ほどアップロードした。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp test.txt s3://yaho-test-bucket3
upload: ./test.txt to s3://yaho-test-bucket3/test.txt
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp test.txt s3://yaho-test-bucket3
upload: ./test.txt to s3://yaho-test-bucket3/test.txt
通常、バージョン管理されていないオブジェクトを削除してから、バケットを削除するが、
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 rb s3://yaho-test-bucket3 --force
delete: s3://yaho-test-bucket3/.bash_history
delete: s3://yaho-test-bucket3/prefix1/test.txt
delete: s3://yaho-test-bucket3/.bash_logout
delete: s3://yaho-test-bucket3/test.txt
delete: s3://yaho-test-bucket3/.swp
delete: s3://yaho-test-bucket3/.zshrc
delete: s3://yaho-test-bucket3/.viminfo
delete: s3://yaho-test-bucket3/prefix1/test2.txt
delete: s3://yaho-test-bucket3/.config/powershell/Microsoft.PowerShell_profile.ps1
delete: s3://yaho-test-bucket3/.bashrc
delete: s3://yaho-test-bucket3/.bash_profile
remove_bucket failed: s3://yaho-test-bucket3 An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty. You must delete all versions in the bucket.
ここまでは分かるんだけど、aws s3 ls
でもバージョン管理しているファイルは見れない。
マネジメントコンソールから確認しても見れない。
どこへ行ってしまったのか・・・。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 ls s3://yaho-test-bucket3
[cloudshell-user@ip-10-0-3-195 ~]$
aws s3 rb
コマンドの挙動2
バージョン管理しているバケットへの結論
普通に削除マーカーを作成して、ファイルを削除する。
※私が無知であっただけで、
内容
バージョン管理の仕組みが、少し分かりました。
公式ドキュメントより
バージョニングを有効にしたバケットは、オブジェクトを誤って削除したり上書きしたりしても、復元が簡単に行えます。例えば、オブジェクトを削除した場合、Amazon S3 は、オブジェクトを完全に削除する代わりに削除マーカーを挿入します。その削除マーカーが、最新のオブジェクトバージョンになります。
概念の説明が図示してあって分かりやすかったです。
実際のCLI手順は、ここを参考にさせてもらいました。 バージョニングを確認してみます。初回アップロード時と、そのあと2回アップロードしたバージョンが確認できます。
最後に削除マーカーが確認できます。こいつを削除すれば元通りになるはず。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3api list-object-versions --bucket yaho-test-bucket3 --prefix test.txt
{
"Versions": [
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "itsCRTQzS1cb.wH.hmfV9kkYEjqpib12",
"IsLatest": false,
"LastModified": "2022-01-12T01:18:03+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "k3EkJGtAHluGsLCCVUYZ9JfglQj2Bf7D",
"IsLatest": false,
"LastModified": "2022-01-12T01:17:42+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"d8e8fca2dc0f896fd7cb4cb0031ba249\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "null",
"IsLatest": false,
"LastModified": "2022-01-12T01:14:50+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
}
],
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "**************",
"ID": "**************"
},
"Key": "test.txt",
"VersionId": "ByfXj9Uk2kZUDmZH3ZnLtVFgEoMeQ6T3",
"IsLatest": true,
"LastModified": "2022-01-12T01:18:43+00:00"
}
]
}
削除マーカーを削除して、
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3api delete-object --bucket yaho-test-bucket3 --key test.txt --version-id ByfXj9Uk2kZUDmZH3ZnLtVFgEoMeQ6T3
{
"DeleteMarker": true,
"VersionId": "ByfXj9Uk2kZUDmZH3ZnLtVFgEoMeQ6T3"
}
元通りになりました。マネジメントコンソールからも見れます。
消えてもよかったファイルなのですが、なんかホッとしてしまいました。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 ls s3://yaho-test-bucket3
2022-01-12 01:18:03 6 test.txt
S3バケットバージョニングの挙動
削除マーカーが最新のとき、アップロードをして、削除するとどうなるのか気になってしまった。
分かったこと
IsLatestキーでオブジェクトの最新かどうかを判断できる。
ETagキーは、MD5ハッシュ値で、整合性チェックに使うことができる。
やってみたこと
削除マーカーが最新である。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3api list-object-versions --bucket yaho-test-bucket3 --prefix test.txt
{
"Versions": [
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "itsCRTQzS1cb.wH.hmfV9kkYEjqpib12",
"IsLatest": false,
"LastModified": "2022-01-12T01:18:03+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "k3EkJGtAHluGsLCCVUYZ9JfglQj2Bf7D",
"IsLatest": false,
"LastModified": "2022-01-12T01:17:42+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"d8e8fca2dc0f896fd7cb4cb0031ba249\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "null",
"IsLatest": false,
"LastModified": "2022-01-12T01:14:50+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
}
],
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "**************",
"ID": "**************"
},
"Key": "test.txt",
"VersionId": "pUoswKscBrjm4SWDfbuj7zE3EbhnTcEQ",
"IsLatest": true,
"LastModified": "2022-01-12T02:02:36+00:00"
}
]
}
アップロードをすると、最新のオブジェクトができる。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 cp test.txt s3://yaho-test-bucket3
upload: ./test.txt to s3://yaho-test-bucket3/test.txt
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3api list-object-versions --bucket yaho-test-bucket3 --prefix test.txt
{
"Versions": [
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "sIWDesf4VGys1gsIsSZ57W2.CpWI3epN",
"IsLatest": true,
"LastModified": "2022-01-12T02:03:22+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "itsCRTQzS1cb.wH.hmfV9kkYEjqpib12",
"IsLatest": false,
"LastModified": "2022-01-12T01:18:03+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "k3EkJGtAHluGsLCCVUYZ9JfglQj2Bf7D",
"IsLatest": false,
"LastModified": "2022-01-12T01:17:42+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"d8e8fca2dc0f896fd7cb4cb0031ba249\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "null",
"IsLatest": false,
"LastModified": "2022-01-12T01:14:50+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
}
],
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "**************",
"ID": "**************"
},
"Key": "test.txt",
"VersionId": "pUoswKscBrjm4SWDfbuj7zE3EbhnTcEQ",
"IsLatest": false,
"LastModified": "2022-01-12T02:02:36+00:00"
}
]
}
削除すると、最新の削除マーカーが作られる。
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3 rm s3://yaho-test-bucket3/test.txt
delete: s3://yaho-test-bucket3/test.txt
[cloudshell-user@ip-10-0-3-195 ~]$ aws s3api list-object-versions --bucket yaho-test-bucket3 --prefix test.txt
{
"Versions": [
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "sIWDesf4VGys1gsIsSZ57W2.CpWI3epN",
"IsLatest": false,
"LastModified": "2022-01-12T02:03:22+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "itsCRTQzS1cb.wH.hmfV9kkYEjqpib12",
"IsLatest": false,
"LastModified": "2022-01-12T01:18:03+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"126a8a51b9d1bbd07fddc65819a542c3\"",
"Size": 6,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "k3EkJGtAHluGsLCCVUYZ9JfglQj2Bf7D",
"IsLatest": false,
"LastModified": "2022-01-12T01:17:42+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
},
{
"ETag": "\"d8e8fca2dc0f896fd7cb4cb0031ba249\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "null",
"IsLatest": false,
"LastModified": "2022-01-12T01:14:50+00:00",
"Owner": {
"DisplayName": "**************",
"ID": "**************"
}
}
],
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "**************",
"ID": "**************"
},
"Key": "test.txt",
"VersionId": "wAXtZU1Cu5cx_ShLLUvlrVkpSCoo4gaT",
"IsLatest": true,
"LastModified": "2022-01-12T02:13:17+00:00"
},
{
"Owner": {
"DisplayName": "**************",
"ID": "**************"
},
"Key": "test.txt",
"VersionId": "pUoswKscBrjm4SWDfbuj7zE3EbhnTcEQ",
"IsLatest": false,
"LastModified": "2022-01-12T02:02:36+00:00"
}
]
}
ここにめっちゃ詳しく書いてある。
公式ドキュメントきちんと読めってことですよね。
本、ドキュメント読む → 動かしてみる
より
動かしてみる → 本、ドキュメント読む
の方が、しっくりくるかもしれない。
aws s3
よりaws s3api
から試していった方が良いのかも。
s3api create-bucket
)
バケットの作成(リージョンが定義されていないというエラーが表示される。
[cloudshell-user@ip-10-0-99-226 ~]$ aws s3api create-bucket --bucket yaho-test
An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.
リージョンを指定したはいいが、エラーが表示される。
[cloudshell-user@ip-10-0-99-226 ~]$ aws s3api create-bucket --bucket yaho-test123 --region ap-northeast-1
An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.
コマンドリファレンスに書いてあったが、LocationConstraintに値を設定しないといけない。
--region
これはグローバルオプションらしい。
[cloudshell-user@ip-10-0-99-226 ~]$ aws s3api create-bucket \
> --bucket yaho-test223 \
> --region ap-northeast-1 \
> --create-bucket-configuration LocationConstraint=ap-northeast-1
{
"Location": "http://yaho-test223.s3.amazonaws.com/"
}
バケットの削除(s3api delete-bucket)
削除の時は、グローバルオプション--region
でもいいみたい。
[cloudshell-user@ip-10-0-99-226 ~]$ aws s3api delete-bucket --bucket yaho-test223 --region ap-northeast-1
[cloudshell-user@ip-10-0-99-226 ~]$