

# AWS CLI のコマンド構造
<a name="cli-usage-commandstructure"></a>

このトピックでは、AWS Command Line Interface (AWS CLI) コマンドの構造と、wait コマンドの使用方法について説明します。

**Topics**
+ [コマンド構造](#cli-usage-commandstructure-structure.title)
+ [Wait コマンド](#cli-usage-commandstructure-wait)

## コマンド構造
<a name="cli-usage-commandstructure-structure.title"></a>

AWS CLI は、コマンドラインでマルチパート構造を使用し、それは次の順序で指定される必要があります。

1. `aws` プログラムのベースコール。

1. 最上位レベルの *コマンド*。一般に AWS によってサポートされる AWS CLI サービスに対応します。

1. 実行する操作を指定する*サブコマンド*。

1. 操作に必要となる一般的な AWS CLI オプションまたはパラメータ。これらは、最初の 3 つのパートに続く限り、任意の順序で指定することができます。排他的パラメータが複数回指定された場合は、*最後の値*のみ適用されます。

```
$ aws <command> <subcommand> [options and parameters]
```

パラメータは数値、文字列、リスト、マップ、JSON 構造体など、様々なタイプの入力値を取得できます。サポートされる内容は、指定したコマンドおよびサブコマンドによって異なります。

### 例
<a name="cli-usage-commandstructure-structure-example"></a>

**Amazon S3**

次の例では、すべての Amazon S3 バケットを一覧表示します。

```
$ aws s3 ls
2018-12-11 17:08:50 amzn-s3-demo-bucket1
2018-12-14 14:55:44 amzn-s3-demo-bucket2
```

Amazon S3 コマンドの詳細については、*AWS CLI* コマンドリファレンスの「[https://docs.aws.amazon.com/cli/latest/reference/s3/index.html](https://docs.aws.amazon.com/cli/latest/reference/s3/index.html)」を参照してください。

**AWS CloudFormation**

以下の [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-change-set.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-change-set.html) コマンドの例は、CloudFormation スタック名を *my-change-set* に変更します。

```
$ aws cloudformation create-change-set --stack-name my-stack --change-set-name my-change-set
```

AWS CloudFormation コマンドの詳細については、*AWS CLI コマンドリファレンス* の「[https://docs.aws.amazon.com/cli/latest/reference/cloudformation/index.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/index.html)」を参照してください。

## Wait コマンド
<a name="cli-usage-commandstructure-wait"></a>

一部の AWS のサービスでは、`wait` コマンドを使用できます。`aws wait` を使用するコマンドは、通常、コマンドが完了するまで待機してから、次のステップに進みます。wait コマンドを使用すると、wait コマンドが失敗した場合に後続のステップに移動するのを防ぐことができるため、マルチパートコマンドやスクリプトに特に便利です。

AWS CLI は、`wait` コマンドのコマンドラインでマルチパート構造を使用します。それは次の順序で指定される必要があります。

1. `aws` プログラムのベースコール。

1. 最上位レベルの *コマンド*。一般に AWS によってサポートされる AWS CLI サービスに対応します。

1. `wait` コマンド。

1. 実行する操作を指定する*サブコマンド*。

1. 操作に必要な一般的な CLI オプションまたはパラメータ。これらは、最初の 3 つのパートに続く限り、任意の順序で指定することができます。排他的パラメータが複数回指定された場合は、*最後の値*のみ適用されます。

```
$ aws <command> wait <subcommand> [options and parameters]
```

パラメータは数値、文字列、リスト、マップ、JSON 構造体など、様々なタイプの入力値を取得できます。サポートされる内容は、指定したコマンドおよびサブコマンドによって異なります。

**注記**  
すべての AWS のサービスが `wait` コマンドをサポートしているわけではありません。ご使用のサービスが `wait` コマンドをサポートしているかどうかについては、[AWS CLI バージョン 2 リファレンスガイド](https://docs.aws.amazon.com/cli/latest/reference/index.html)を参照してください。

### 例
<a name="cli-usage-commandstructure-wait-example"></a>

**AWS CloudFormation**

次の [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/change-set-create-complete.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/change-set-create-complete.html) コマンドの例は、*my-stack* スタック内の *my-change-set* 変更セットの実行準備が整っていることを確認できる場合に限り、一時停止と再開を行います。

```
$ aws cloudformation wait change-set-create-complete --stack-name my-stack --change-set-name my-change-set
```

AWS CloudFormation `wait`コマンドの詳細については、*AWS CLI* コマンドリファレンスの「[https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/index.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/index.html)」を参照してください。

**AWS CodeDeploy**

次の [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/change-set-create-complete.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/change-set-create-complete.html) コマンド例は、*d-A1B2C3111* のデプロイが正常に完了するまで一時停止します。

```
$ aws deploy wait deployment-successful --deployment-id d-A1B2C3111
```

AWS CodeDeploy `wait`コマンドの詳細については、*AWS CLI コマンドリファレンス*の「[https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/index.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/index.html)」を参照してください。