

• 2026 年 4 月 30 日之後， AWS Systems Manager CloudWatch Dashboard 將不再可用。客戶可以繼續使用 Amazon CloudWatch 主控台來檢視、建立和管理其 Amazon CloudWatch 儀表板，就像現在一樣。如需詳細資訊，請參閱 [Amazon CloudWatch Dashboard 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

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

# 在受管節點上執行命令
<a name="running-commands"></a>

本節包含如何從 AWS Systems Manager 主控台傳送命令至受管節點的相關資訊。這區段還包含如何取消命令的相關資訊。

請注意，如果您的節點使用 var 目錄的 `noexec` 掛載選項設定，Run Command 將無法成功執行命令。

**重要**  
當您使用 Run Command 發出命令時，請勿包含格式為純文字的敏感資訊，例如密碼、組態資料或其他密碼。您帳戶中的所有 Systems Manager API 活動都會記錄在 S3 儲存貯體中的 AWS CloudTrail 日誌。這意味著任何具有權存取該 S3 儲存貯體的使用者都可以查看這些密碼的純文字值。因此，建議您建立並使用 `SecureString` 參數來加密您在 Systems Manager 操作中使用的敏感資料。  
如需詳細資訊，請參閱[使用 IAM 政策限制對 Parameter Store 參數的存取](sysman-paramstore-access.md)。

**執行歷史記錄保留**  
每個命令的歷史記錄最多可供使用 30 天。另外，您可以將所有日誌檔案的複本存放在 Amazon Simple Storage Service 中，或記錄 AWS CloudTrail中所有 API 呼叫的稽核軌跡。

**相關資訊**  
如需有關使用其他工具傳送命令的資訊，請參閱下列主題：
+ [逐步解說： AWS Tools for Windows PowerShell 搭配 使用 Run Command](walkthrough-powershell.md) 或 [AWS Systems ManagerAWS Tools for PowerShell Cmdlet 參考 區段](https://docs.aws.amazon.com/powershell/latest/reference/items/AWS_Systems_Manager_cmdlets.html)中的範例。
+ [逐步解說： AWS CLI 搭配 使用 Run Command](walkthrough-cli.md)或 [SSM CLI 參考](https://docs.aws.amazon.com/cli/latest/reference/ssm/)中的範例

**Topics**
+ [

# 從主控台執行命令
](running-commands-console.md)
+ [

# 使用特定文件版本執行命令
](run-command-version.md)
+ [

# 大規模執行命令
](send-commands-multiple.md)
+ [

# 取消命令
](cancel-run-command.md)

# 從主控台執行命令
<a name="running-commands-console"></a>

您可以從 使用 中的Run Command工具 AWS 管理主控台 來設定受管節點 AWS Systems Manager，而不必登入這些節點。本主題包含範例，說明如何使用 Run Command 在受管節點上[更新 SSM Agent](run-command-tutorial-update-software.md#rc-console-agentexample)。

**開始之前**  
使用 Run Command 傳送命令之前，確認您的受管節點滿足所有 Systems Manager [設定要求](systems-manager-setting-up-nodes.md)。

**使用 Run Command 傳送命令**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **Run Command**。

1. 選擇**執行命令**。

1. 在 **Command document** (命令文件) 清單中，選擇 Systems Manager 文件。

1. 在 **Command parameters (命令參數)** 區段，指定所需的參數值。

1. 在 **Targets** (目標) 區段中，透過手動指定標籤、選取執行個體或邊緣裝置，或指定資源群組，選擇您要執行這項操作的受管節點。
**提示**  
如果您預期看到的受管節點未列出，請參閱 [疑難排解受管節點的可用性](fleet-manager-troubleshooting-managed-nodes.md) 以取得疑難排解秘訣。

1. 對於**其他參數**：
   + 在 **Comment** (註解) 中，輸入此命令的相關資訊。
   + 在**逾時 (秒)** 中，指定在命令執行全面失敗之前，系統要等候的秒數。

1. 對於 **Rate control** (速率控制)：
   + 在**並行**中，指定可同時執行命令的受管節點數目或百分比。
**注意**  
如果您透過指定套用至受管節點的標籤或指定 AWS 資源群組來選取目標，而且不確定目標的受管節點數量，則透過指定百分比來限制可同時執行文件的目標數量。
   + 在 **Error threshold** (錯誤閾值) 中，指定在特定數目或百分比之節點上的命令失敗之後，停止在其他受管節點上執行命令。例如，如果您指定三個錯誤，則 Systems Manager 會在收到第四個錯誤時停止傳送命令。仍在處理命令的受管節點也可能會傳送錯誤。

1. (選用) 選擇要套用至您的監控命令的 CloudWatch 警示。若要將 CloudWatch 警示附加至您的命令，執行命令的 IAM 主體必須具備 `iam:createServiceLinkedRole` 動作的許可。如需有關 CloudWatch 警示的詳細資訊，請參閱[使用 Amazon CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)。請注意，如果您的警示啟用，則不會執行任何待處理命令叫用。

1. (選用) 針對**輸出選項**，若要將命令輸出儲存至檔案，請選取**將命令輸出寫入至 S3 儲存貯體**方塊。在方塊中輸入儲存貯體和字首 (資料夾) 名稱。
**注意**  
授予能力以將資料寫入至 S3 儲存貯體的 S3 許可，會是指派給執行個體之執行個體設定檔 (適用於 EC2 執行個體) 或 IAM 服務角色 (啟用混合模式的機器) 的許可，而不是執行此任務之 IAM 使用者的許可。如需詳細資訊，請參閱[設定 Systems Manager 所需的執行個體許可](setup-instance-permissions.md)或[建立混合環境的 IAM 服務角色](hybrid-multicloud-service-role.md)。此外，若指定的 S3 儲存貯體位於不同的 AWS 帳戶內，請確保與受管節點相關聯的執行個體設定檔或 IAM 服務角色是否具有寫入該儲存貯體的必要許可。

1. 在**SNS 通知**區段中，如果您要傳送有關命令執行狀態的通知，請選取**啟用 SNS 通知**核取方塊。

   如需為 Run Command 設定 Amazon SNS 通知的詳細資訊，請參閱 [使用 Amazon SNS 通知監控 Systems Manager 狀態變更](monitoring-sns-notifications.md)。

1. 選擇**執行**。

如需取消命令的詳細資訊，請參閱 [取消命令](cancel-run-command.md)。

## 重新執行命令
<a name="run-command-rerun"></a>

Systems Manager 包含兩個選項，可協助您從 Systems Manager 主控台的 **Run Command** (執行命令) 頁面重新執行命令。
+ **Rerun **(重新執行)：此按鈕可讓您執行相同的命令，而不對其進行變更。
+ **Copy to new (複製到新命令)**：此按鈕會將一個命令的設定複製到新命令，並讓您選擇在執行之前編輯這些設定。

**重新執行命令**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **Run Command**。

1. 選擇要重新執行的命令。從命令詳細資訊頁面執行命令之後，您可以立即重新執行命令。或者，您也可以從 **Command history** (命令歷程記錄) 索引標籤選擇先前執行的命令。

1. 選擇 **Rerun (重新執行)** 以在不進行變更的情況下執行相同的命令，或選擇 **Copy to new (複製到新的)** 以在執行命令之前先行編輯命令設定。

# 使用特定文件版本執行命令
<a name="run-command-version"></a>

您可以使用文件版本參數來在命令執行時，指定要使用的 AWS Systems Manager 文件版本。您可為此參數指定下列其中一個選項：
+ \$1DEFAULT
+ \$1LATEST
+ 版本編號

請執行以下處理程序來使用文件版本參數執行命令。

------
#### [ Linux ]

**在本機 Linux 機器 AWS CLI 上使用 執行命令**

1. 如果您尚未安裝並設定 AWS Command Line Interface (AWS CLI)，請安裝並設定 。

   如需相關資訊，請參閱[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 列出所有可用的文件

   此命令會根據 AWS Identity and Access Management (IAM) 許可列出您帳戶可用的所有文件。

   ```
   aws ssm list-documents
   ```

1. 執行下列命令來檢視不同版本的文件。將*文件名稱*取代為自己的資訊。

   ```
   aws ssm list-document-versions \
       --name "document name"
   ```

1. 執行下列命令來執行使用 SSM 文件版本的命令。將每個*範例資源預留位置*取代為您自己的資訊。

   ```
   aws ssm send-command \
       --document-name "AWS-RunShellScript" \
       --parameters commands="echo Hello" \
       --instance-ids instance-ID \
       --document-version '$LATEST'
   ```

------
#### [ Windows ]

**在本機 Windows 機器 AWS CLI 上使用 執行命令**

1. 如果您尚未安裝並設定 AWS Command Line Interface (AWS CLI)，請安裝並設定 。

   如需相關資訊，請參閱[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 列出所有可用的文件

   此命令會根據 AWS Identity and Access Management (IAM) 許可列出您帳戶可用的所有文件。

   ```
   aws ssm list-documents
   ```

1. 執行下列命令來檢視不同版本的文件。將*文件名稱*取代為自己的資訊。

   ```
   aws ssm list-document-versions ^
       --name "document name"
   ```

1. 執行下列命令來執行使用 SSM 文件版本的命令。將每個*範例資源預留位置*取代為您自己的資訊。

   ```
   aws ssm send-command ^
       --document-name "AWS-RunShellScript" ^
       --parameters commands="echo Hello" ^
       --instance-ids instance-ID ^
       --document-version "$LATEST"
   ```

------
#### [ PowerShell ]

**使用 Tools for PowerShell 執行命令**

1. 如果您尚未安裝並設定 AWS Tools for PowerShell (Tools for Windows PowerShell)。

   如需相關資訊，請參閱[安裝 AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html)。

1. 列出所有可用的文件

   此命令會根據 AWS Identity and Access Management (IAM) 許可列出您帳戶可用的所有文件。

   ```
   Get-SSMDocumentList
   ```

1. 執行下列命令來檢視不同版本的文件。將*文件名稱*取代為自己的資訊。

   ```
   Get-SSMDocumentVersionList `
       -Name "document name"
   ```

1. 執行下列命令來執行使用 SSM 文件版本的命令。將每個*範例資源預留位置*取代為您自己的資訊。

   ```
   Send-SSMCommand `
       -DocumentName "AWS-RunShellScript" `
       -Parameter @{commands = "echo helloWorld"} `
       -InstanceIds "instance-ID" `
       -DocumentVersion $LATEST
   ```

------

# 大規模執行命令
<a name="send-commands-multiple"></a>

您可以使用 中的Run Command工具 AWS Systems Manager，在受管節點的機群上執行命令`targets`。`targets` 參數接受以您為受管節點指定的標記為基礎的 `Key,Value` 組。當您執行命令時，系統會尋找並嘗試在符合指定標記的所有受管節點上執行命令。如需標記受管執行個體的詳細資訊，請參閱[《標記資源使用者指南》中的標記您的 AWS](https://docs.aws.amazon.com/tag-editor/latest/userguide/tag-editor.html)資源。 * AWS *如需有關標記受管 IoT 裝置的資訊，請參閱《 *AWS IoT Greengrass Version 2 開發人員指南*》中的[標記您的 AWS IoT Greengrass Version 2 資源](https://docs.aws.amazon.com/greengrass/v2/developerguide/tag-resources.html)。

您也可以使用 `targets` 參數設為目標的特定受管節點 ID，清單中所述的下一個部分。

若要在數百或者數千個受管節點間控制命令執行，Run Command 還包含可限制可以同時處理請求之節點數的參數，以及取消命令之前命令可以擲回的錯誤數。

**Topics**
+ [

## 以多個受管節點為目標
](#send-commands-targeting)
+ [

## 使用速率控制
](#send-commands-rate)

## 以多個受管節點為目標
<a name="send-commands-targeting"></a>

您可以透過指定標籤、 AWS 資源群組名稱或受管節點 ID，執行命令和目標受管節點。

下列範例顯示Run Command從 AWS Command Line Interface () 使用 時的命令格式AWS CLI 。將每個*範例資源預留位置*取代為您自己的資訊。使用 `[...]` 將此區段中的範本命令截斷。

**範例 1：以標籤為目標**

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:tag-name,Values=tag-value \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:tag-name,Values=tag-value ^
    [...]
```

------

**範例 2：依名稱鎖定 AWS 資源群組**

您可以為每個命令指定最多一個資源群組名稱。建立資源群組時，我們建議包括在分組條件中包含 `AWS::SSM:ManagedInstance` 和 `AWS::EC2::Instance` 作為資源類型。

**注意**  
若要傳送以資源群組為目標的命令，您必須已獲授予 AWS Identity and Access Management (IAM) 許可，才能列出或檢視屬於該群組的資源。如需詳細資訊，請參閱《*AWS Resource Groups 使用者指南*》中的[設定許可](https://docs.aws.amazon.com/ARG/latest/userguide/gettingstarted-prereqs.html#gettingstarted-prereqs-permissions)。

------
#### [ Linux & macOS ]

```
aws ssm send-command \    
    --document-name document-name \
    --targets Key=resource-groups:Name,Values=resource-group-name \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^    
    --document-name document-name ^
    --targets Key=resource-groups:Name,Values=resource-group-name ^
    [...]
```

------

**範例 3：依 AWS 資源類型鎖定資源群組**

您可以為每個命令指定最多五個資源群組類型。建立資源群組時，我們建議包括在分組條件中包含 `AWS::SSM:ManagedInstance` 和 `AWS::EC2::Instance` 作為資源類型。

**注意**  
為了傳送以資源群組為目標的命令，您必須獲得 IAM 許可來列出或檢視屬於該群組的資源。如需詳細資訊，請參閱《[AWS Resource Groups 使用者指南](https://docs.aws.amazon.com/ARG/latest/userguide/gettingstarted-prereqs.html#gettingstarted-prereqs-permissions)》中的*設定許可*。

------
#### [ Linux & macOS ]

```
aws ssm send-command \    
    --document-name document-name \
    --targets Key=resource-groups:ResourceTypeFilters,Values=resource-type-1,resource-type-2 \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^    
    --document-name document-name ^
    --targets Key=resource-groups:ResourceTypeFilters,Values=resource-type-1,resource-type-2 ^
    [...]
```

------

**範例 4：以執行個體 ID 為目標**

下列範例示範如何將 `instanceids` 金鑰與 `targets` 參數搭配使用才能鎖定受管節點。您可以使用此金鑰以受管 AWS IoT Greengrass 核心裝置為目標，因為每個裝置都會指派 mi-*ID\$1number*。您可以在 Fleet Manager ( AWS Systems Manager中的工具) 中檢視裝置 ID。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=instanceids,Values=instance-ID-1,instance-ID-2,instance-ID-3 \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=instanceids,Values=instance-ID-1,instance-ID-2,instance-ID-3 ^
    [...]
```

------

如果您使用名為 `Environment` 的 `Key` 以及 `Development`、`Test` 和 `Pre-production` 的 `Values` 以及 `Production`，為不同環境的受管節點加上標記，則您可以使用 `targets` 參數搭配以下語法，將命令傳送至這些環境中的所有節點*之一*。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:Environment,Values=Development \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:Environment,Values=Development ^
    [...]
```

------

您可以透過新增到 `Values` 清單，在其他環境中以其他受管節點為目標。使用逗號分隔的獨立項目。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:Environment,Values=Development,Test,Pre-production \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:Environment,Values=Development,Test,Pre-production ^
    [...]
```

------

**變異**：使用多個 `Key` 條件精簡您的目標

您可以透過包含多個 `Key` 條件來精簡您命令的目標數。如果您包含多個 `Key` 條件，系統會將符合*所有*條件的受管節點視為目標。以下命令為將標上金融部門*和*資料庫伺服器角色的所有受管節點視為目標。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:Department,Values=Finance Key=tag:ServerRole,Values=Database \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:Department,Values=Finance Key=tag:ServerRole,Values=Database ^
    [...]
```

------

**變異**：使用多個 `Key` 和 `Value` 條件

在之前的範例中展開，您可以透過在 `Values` 條件中包含額外的項目，來將多個部門和多個伺服器角色視為目標。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database ^
    [...]
```

------

**變化**：使用多個 `Values` 條件鎖定標記的受管節點

如果您使用名為 `Department` 的 `Key` 以及 `Sales` 和 `Finance` 的 `Values`，為不同環境的受管節點加上標記，則您可以使用 `targets` 參數搭配以下語法，將命令傳送至這些環境中的所有節點。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:Department,Values=Sales,Finance \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:Department,Values=Sales,Finance ^
    [...]
```

------

您最多可以指定五個索引鍵，每個索引鍵可以指定五個數值。

如果標籤索引鍵 (標籤名稱) 或標籤值包含空格，則將標籤索引鍵或值括在引號中，如下範例所示。

**範例**：`Value` 標籤中的空格

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:OS,Values="Windows Server 2016" \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:OS,Values="Windows Server 2016" ^
    [...]
```

------

**範例**：`tag` 索引鍵中的空格和 `Value`

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key="tag:Operating System",Values="Windows Server 2016" \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key="tag:Operating System",Values="Windows Server 2016" ^
    [...]
```

------

**範例** ：在 `Values` 清單的單一項目中的空格。

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --targets Key=tag:Department,Values="Sales","Finance","Systems Mgmt" \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --targets Key=tag:Department,Values="Sales","Finance","Systems Mgmt" ^
    [...]
```

------

## 使用速率控制
<a name="send-commands-rate"></a>

您可以控制命令傳送到群組中受管節點的速率，方法是使用*並行控制項*和*錯誤控制項*。

**Topics**
+ [

### 使用並行控制
](#send-commands-velocity)
+ [

### 使用錯誤控制
](#send-commands-maxerrors)

### 使用並行控制
<a name="send-commands-velocity"></a>

您可以使用 `max-concurrency` 參數 (**Run a command** (執行命令) 頁面中的 **Concurrecy** (並行) 選項) 控制同時執行之受管節點的數量。您可以指定絕對數量的受管節點 (例如 **10**) 或目標集的百分比 (例如 **10%**)。佇列系統會將命令傳遞至單一節點並等到系統確認初始叫用，再將該命令傳送至另外兩個節點。系統會以指數方式將命令傳送至更多受管節點，直到系統達到 `max-concurrency` 值為止。`max-concurrency` 的預設值為 50。以下範例說明您為 `max-concurrency` 參數指定數值的方式：

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --max-concurrency 10 \
    --targets Key=tag:Environment,Values=Development \
    [...]
```

```
aws ssm send-command \
    --document-name document-name \
    --max-concurrency 10% \
    --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --max-concurrency 10 ^
    --targets Key=tag:Environment,Values=Development ^
    [...]
```

```
aws ssm send-command ^
    --document-name document-name ^
    --max-concurrency 10% ^
    --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database ^
    [...]
```

------

### 使用錯誤控制
<a name="send-commands-maxerrors"></a>

透過使用 `max-errors` 參數(**Run a command** (執行命令) 頁面中的 **Error threshold** (錯誤閾值) 欄位) 設定錯誤限制，您也可以控制數百個或數千個受管節點的命令執行。參數會指定在系統停止將命令傳送至其他受管節點前允許的錯誤數。您可以指定錯誤的絕對數目 (例如 **10**)，或目標集的百分比 (例如 **10%**)。舉例來說，如果您指定 **3**，系統會在收到第 4 個錯誤時停止傳送命令。如果您指定 **0**，系統會在第一個錯誤結果傳回後停止將命令傳送至其他受管節點。如果您將命令傳送至 50 個受管節點，並將 `max-errors` 設為 **10%**，系統會在收到第六個錯誤時停止將命令傳送至其他節點。

達到 `max-errors` 時，系統會允許完成已在執行命令的呼叫，但一些呼叫也可能會失敗。如果您需要確保不會有超過 `max-errors` 個失敗的呼叫，請將 `max-concurrency` 設定為 **1**，以每次執行一個呼叫。錯誤上限預設值為 0。以下範例說明您為 `max-errors` 參數指定數值的方式：

------
#### [ Linux & macOS ]

```
aws ssm send-command \
    --document-name document-name \
    --max-errors 10 \
    --targets Key=tag:Database,Values=Development \
    [...]
```

```
aws ssm send-command \
    --document-name document-name \
    --max-errors 10% \
    --targets Key=tag:Environment,Values=Development \
    [...]
```

```
aws ssm send-command \
    --document-name document-name \
    --max-concurrency 1 \
    --max-errors 1 \
    --targets Key=tag:Environment,Values=Production \
    [...]
```

------
#### [ Windows ]

```
aws ssm send-command ^
    --document-name document-name ^
    --max-errors 10 ^
    --targets Key=tag:Database,Values=Development ^
    [...]
```

```
aws ssm send-command ^
    --document-name document-name ^
    --max-errors 10% ^
    --targets Key=tag:Environment,Values=Development ^
    [...]
```

```
aws ssm send-command ^
    --document-name document-name ^
    --max-concurrency 1 ^
    --max-errors 1 ^
    --targets Key=tag:Environment,Values=Production ^
    [...]
```

------

# 取消命令
<a name="cancel-run-command"></a>

只要該服務會顯示為待定或執行中狀態，您就可以嘗試取消命令。不過，即使命令仍處於其中一個狀態，我們無法保證命令是否會取消且基本程序會停止。

**使用主控台來取消命令**

1. 開啟位於 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 的 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **Run Command**。

1. 選取您要取消的命令呼叫。

1. 選擇 **Cancel command (取消命令)**。

**使用 AWS CLI 來取消命令**  
執行下列命令。將每個*範例資源預留位置*取代為您自己的資訊。

------
#### [ Linux & macOS ]

```
aws ssm cancel-command \
    --command-id "command-ID" \
    --instance-ids "instance-ID"
```

------
#### [ Windows ]

```
aws ssm cancel-command ^
    --command-id "command-ID" ^
    --instance-ids "instance-ID"
```

------

如需取消命令之狀態的詳細資訊，請參閱 [了解命令狀態](monitor-commands.md)。