

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AWS CLI 中的命令結構
<a name="cli-usage-commandstructure"></a>

本主題包括 AWS Command Line Interface (AWS CLI) 命令如何結構化，以及如何使用等待命令。

**Topics**
+ [命令結構](#cli-usage-commandstructure-structure.title)
+ [等候命令](#cli-usage-commandstructure-wait)

## 命令結構
<a name="cli-usage-commandstructure-structure.title"></a>

AWS CLI 在命令列上使用必須依以下順序指定的分段結構：

1. 對 `aws` 程式的基本呼叫。

1. 頂層*命令*，通常對應至 AWS CLI 支援的 AWS 服務。

1. 指定執行哪些操作的*子命令*。

1. 操作所需的一般 AWS CLI 選項或參數。只要位在前三個部分後面，您可以依任意順序指定這些項目。如果排他參數受到多次指定，只會套用*最終數值*。

```
$ 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)。

## 等候命令
<a name="cli-usage-commandstructure-wait"></a>

部分 AWS 服務可使用 `wait` 指令。任何使用 `aws wait` 的命令通常都會等到命令完成後，再進行下一個步驟。這對於分段命令或指令碼特別有用，因為如果等候命令失敗，您可以使用等候命令來避免進行後續步驟。

AWS CLI 會在命令列上使用必須依此順序指定的 `wait` 命令分段結構：

1. 對 `aws` 程式的基本呼叫。

1. 頂層*命令*，通常對應至 AWS CLI 支援的 AWS 服務。

1. `wait` 命令。

1. 指定執行哪些操作的*子命令*。

1. 操作所需的一般 CLI 選項或參數。只要位在前三個部分後面，您可以依任意順序指定這些項目。如果排他參數受到多次指定，只會套用*最終數值*。

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

參數採用各種類型的輸入數值，例如數字、字串、清單、映射和 JSON 結構。支援哪些項目取決於您指定的命令和子命令。

**注意**  
並非所有 AWS 服務都支援 `wait` 命令。請參閱 [AWS CLI 第 2 版參考指南](https://docs.aws.amazon.com/cli/latest/reference/index.html)，了解您的服務是否支援 `wait` 命令。

### 範例
<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)。