Wasabi は S3 互換であり、Amazon S3 と同様に API を実行できます。したがって、AWS CLI も利用できるとこちらのドキュメントにも記載があります。
一度つかったことがある人であれば、AWS CLI でリソースを操作できるのは非常に便利です。Wasabi で AWS CLI を利用するにはどういった設定等が必要か確認してみたいと思います。
前提
ここでは以下が必要になります。
試してみる
今回の私の環境は WSL 上の Ubuntu 22.04 で、AWS CLI は v2 です。早速設定していきましょう。
コマンドラインで以下のように aws configure を –profile オプションをつけて実行してみます。
$ aws configure --profile wasabi
AWS Access Key ID [None]:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AWS Secret Access Key [None]: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Default region name [None]:
Default output format [None]:
エラーなくコマンドは完了しました。 Wasabi のドキュメントにかかれているとおり、エンドポイント名を指定して、s3 のサブコマンドを実行してみます。(s3.wasabisys.com は us-east-1 になります。他のリージョンを指定したい場合は「Wasabi の各ストレージリージョンのサービス URL を教えてください。」 を参考にしてください。)
$ aws s3 ls --profile wasabi --endpoint-url=https://s3.wasabisys.com
2024-02-08 09:12:45 dev-pubstorage-001
2023-11-10 13:29:45 dev-storage-001
2024-04-11 16:02:49 hogehogeok
問題なくバケットをリストすることができました! しかし、エンドポイント名を毎回指定するのも大変ではないか?と思いましたが、Wasabi のドキュメント を見てみるとどうやら AWS CLI のプラグインを利用することでエンドポイントを設定ファイル内に定義することでコマンド実行時のエンドポイント名を省略できるようです!
AWS CLI のプラグインを試してみる
利用するプラグインは awscli-plugin-endpoint というものです。手順は GitHub に書かれているのでそれに沿って進めてみます。
$ pip install awscli-plugin-endpoint
Defaulting to user installation because normal site-packages is not writeable
Collecting awscli-plugin-endpoint
Downloading awscli_plugin_endpoint-0.4-py2.py3-none-any.whl (7.6 kB)
中略
Installing collected packages: pyasn1, docutils, colorama, rsa, botocore, awscli, awscli-plugin-endpoint
Attempting uninstall: botocore
Found existing installation: botocore 1.34.72
Uninstalling botocore-1.34.72:
Successfully uninstalled botocore-1.34.72
Successfully installed awscli-1.32.100 awscli-plugin-endpoint-0.4 botocore-1.34.100 colorama-0.4.6 docutils-0.16 pyasn1-0.6.0 rsa-4.7.2
プラグインのインストールは成功しました。次にエンドポイントを設定してみたいと思います。
まず、以下を実行します。
$ aws configure set plugins.endpoint awscli_plugin_endpoint
そうすると、AWS CLI の設定ファイル (config) に以下のように記載が追加されます。追加されるのは endpoint の行です。これでエンドポイントを設定することができるようになります。
$ cat ./.aws/config
[default]
region = ap-northeast-1
[profile wasabi]
[plugins]
endpoint = awscli_plugin_endpoint
次にエンドポイントを指定します。
$ aws configure --profile wasabi set s3.endpoint_url https://s3.wasabisys.com
No module named 'awscli_plugin_endpoint'
が、エラーがでました。。インストール方法が記載されている GitHub awscli-plugin-endpoint を読み直すと以下の記載がありました。
Regardless of the installation method, make note of the package installation path (e.g. ~/Library/Python/3.7/lib/python/site-packages). It will be needed if you are using AWS CLI v2.
awscli-plugin-endpoint
plugins.cli_legacy_plugin_path で上記に書かれている site-packages のパスを指定する必要があったようです。
plugins.cli_legacy_plugin_path を設定してみます。
$ aws configure set plugins.cli_legacy_plugin_path /home/yokosugc/.local/lib/python3.10/site-packages
$ cat ./.aws/config
[amplify-dev]
region = ap-northeast-1
[default]
region = ap-northeast-1
[profile wasabi]
[plugins]
endpoint = awscli_plugin_endpoint
cli_legacy_plugin_path = /home/yokosugc/.local/lib/python3.10/site-packages
cli_legacy_plugin_path が設定されたことが config からわかります。改めてエンドポイントの指定をしてみます。
$ aws configure --profile wasabi set s3.endpoint_url https://s3.wasabisys.com
$ cat ./.aws/config
[amplify-dev]
region = ap-northeast-1
[default]
region = ap-northeast-1
[profile wasabi]
s3 =
endpoint_url = https://s3.wasabisys.com
[plugins]
endpoint = awscli_plugin_endpoint
cli_legacy_plugin_path = /home/yokosugc/.local/lib/python3.10/site-packages
s3 = 、endpoint_url = という行が追加されたことがわかります。しかし、以下の記載がある通り、これだけでは低レベルの S3 CLI は実行できなようです。
One more thing, the endpoint is technically per sub command. Take S3 as example, above S3 configuration will not work for S3 low level CLI aws s3api. To make s3api work with this endpoint, you should add endpoint to this sub command as well:
awscli-plugin-endpoint
s3spiの設定をしてみます。
$ aws configure --profile wasabi set s3spi.endpoint_url https://s3.wasabisys.com
$ cat ./.aws/config
[amplify-dev]
region = ap-northeast-1
[default]
region = ap-northeast-1
[profile wasabi]
s3 =
endpoint_url = https://s3.wasabisys.com
s3spi =
endpoint_url = https://s3.wasabisys.com
[plugins]
endpoint = awscli_plugin_endpoint
cli_legacy_plugin_path = /home/yokosugc/.local/lib/python3.10/site-packages
これでエンドポイントを指定せずに実行できそうです。
エンドポイントを指定せずに AWS CLI を Wasabi に対して実行してみる
実行してみます。
$ aws s3 ls --profile wasabi
2024-02-08 09:12:45 dev-pubstorage-001
2023-11-10 13:29:45 dev-storage-001
2024-04-11 16:02:49 hogehogeok
エンドポイントありで実行したときと同じ結果が返ってきました。
バケットも作成できます。
$ aws s3 mb s3://us-bitob --profile wasabi
make_bucket: us-bitob
Wasabi では IAM もあるので iam のサブコマンドも実行してみます。
aws iam list-users --profile wasabi
An error occurred (InvalidClientTokenId) when calling the ListAccessKeys operation: The security token included in the request is invalid.
エラーが返ってきました、一瞬悩みましたが、そもそも IAM のエンドポイントは別なので IAM エンドポイントも指定してあげる必要がありました。上記は AWS の IAM エンドポイントにリクエストを投げているのでエラーが返ってきてました。
Wasabi の IAM エンドポイントを指定してみる
S3 のエンドポイント同じように指定してみます。(iam.wasabisys.com が wasabi の IAM エンドポイントです)
$ aws configure --profile wasabi set iam.endpoint_url https://iam.wasabisys.com
$ cat .aws/config
[default]
region = ap-northeast-1
[profile wasabi]
s3 =
endpoint_url = https://s3.wasabisys.com
s3spi =
endpoint_url = https://s3.wasabisys.com
region = us-east-1
iam =
endpoint_url = https://iam.wasabisys.com
[plugins]
endpoint = awscli_plugin_endpoint
cli_legacy_plugin_path = /home/yokosugc/.local/lib/python3.10/site-packages
iam= とそれに対応する endopoint_url= が追加されましたね!改めて実行してみます!
$ aws iam list-access-keys --profile wasabi
{
"AccessKeyMetadata": [
{
"UserName": "",
"AccessKeyId": "xxxxxxxxxxxxxxxxxx",
"Status": "Active",
"CreateDate": "2024-05-08T08:53:26+00:00"
}
]
}
無事結果が返ってきました!
ちょっと寄り道
こちらの GitHub awscli-plugin-endpoint は元 AWS の方が作成、管理しているようですね。
まとめ
AWS CLI を活用して Wasabi を同様に操作できることがわかりました!また、プラグインを使うことでエンドポイント名を省略できたりと操作感も良くなることもわかりました。
Wasabi でも AWS と同様にアクションを試したいときには AWS CLI は容易に確認できるのは良いですね!