こんにちは、CX 事業本部 Delivery 部の若槻です。
今回は、構文を絶対に間違えていないはずの AWS CLI コマンドの実行が失敗する場合の確認ポイントについてです。
失敗パターン
「command not found: <オプション>」エラー
次のように command not found: <option>
となる場合。
$ aws stepfunctions list-state-machines \
--max-items 1
Note: AWS CLI version 2, the latest major version of the AWS CLI, is now stable and recommended for general use. For more information, see the AWS CLI version 2 installation instructions at: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options:
zsh: command not found: --max-items
確認ポイント
\
の後ろにスペースが混入していないか確認しましょう。
aws stepfunctions list-state-machines \ # ←ここにスペースが入っている場合はエラーとなる。
--max-items 1
「An error occurred (AccessDeniedException) when calling the <サブコマンド> operation」エラー
次のように An error occurred (AccessDeniedException) when calling the <sub command> operation
となる場合。
$ aws iottwinmaker list-workspaces
An error occurred (AccessDeniedException) when calling the ListWorkspaces operation:
確認ポイント
サービスが GA されているリージョンを指定しているか確認しましょう。
「aws: error: argument command: Invalid choice, valid choices are:」エラー
次のように aws: error: argument command: Invalid choice, valid choices are:
となる場合。
$ aws bedrock list-custom-models
Note: AWS CLI version 2, the latest major version of the AWS CLI, is now stable and recommended for general use. For more information, see the AWS CLI version 2 installation instructions at: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: argument command: Invalid choice, valid choices are:
確認ポイント
新しいサービスの場合は、AWS CLI のバージョンが古い可能性があります。最新のバージョンにアップデートしましょう。
$ aws --version
aws-cli/1.29.16 Python/3.10.12 Darwin/22.6.0 botocore/1.31.16
まとめ
構文を絶対に間違えていないはずの AWS CLI コマンドの実行が失敗する場合は、次のポイントを確認してみましょう。
\
の後ろにスペースが混入していないか- サービスが GA されているリージョンを指定しているか
- AWS CLI のバージョンが古くないか
以上