

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 大规模运行自动化操作
<a name="running-automations-scale"></a>

借助 AWS Systems Manager Automation，您可以使用*目标*在 AWS 资源的实例集上运行自动化。此外，您还可以通过指定并发值和错误阈值来控制自动化在整个队列上的部署。并发和错误阈值功能统称为*速率控制*。并发值决定允许同时运行自动化的资源数量。Automation 还提供了一种可以选择加入的自适应并发模式。自适应并发会自动将自动化配额从 100 个同时运行的自动化配额扩展到 500 个。错误阈值决定在 Systems Manager 停止将自动化发送到其他资源之前允许自动化执行失败的次数。

有关并发性和错误阈值的更多信息，请参阅 [大规模控制自动化](running-automations-scale-controls.md)。有关目标的更多信息，请参阅 [映射自动化目标](running-automations-map-targets.md)。

以下程序介绍了如何开启自适应并发性，以及如何使用 Systems Manager 控制台和 AWS Command Line Interface (AWS CLI) 运行具有目标和速率控制的自动化。

## 运行具有目标和速率控制自动化（控制台）
<a name="scale-console"></a>

以下过程介绍了如何使用 Systems Manager 控制台运行具有目标和速率控制的自动化。

**运行具有目标和速率控制的自动化**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，选择**自动化**，然后选择**执行自动化**。

1. 在**自动化文档**列表中，请选择运行手册。在**文档类别**窗格中选择一个或多个选项，以便根据 SSM 文档的用途对其进行筛选。要查看您拥有的运行手册，请选择**我拥有的**选项卡。要查看与您的账户共享的运行手册，请选择**与我共享**选项卡。要查看所有运行手册，请选择**所有文档**选项卡。
**注意**  
您可以通过选择运行手册名称来查看有关该手册的信息。

1. 在**文档详细信息**部分中，验证**文档版本**已设置为要运行的版本。系统包括以下版本选项：
   + **运行时的默认版本** – 如果定期更新自动化运行手册并分配新的默认版本，请选择此选项。
   + **运行时的最新版本** – 如果定期更新自动化运行手册并且想要运行最新更新的版本，请选择此选项。
   + **1（默认）** – 选择此选项可执行文档的第一个版本，即默认版本。

1. 选择**下一步**。

1. 在**执行模式**部分中，选择**速率控制**。如果要使用目标和速率控制，则必须使用此模式或**多账户和多区域**。

1. 在**目标**部分中，选择希望如何设置要在其中运行自动化的 AWS 资源。这些选项是必需的。

   1. 使用**参数**列表选择一个参数。**参数**列表中的项目由此过程开始时选择的自动化运行手册中的参数确定。通过选择参数，可以定义在其上运行自动化工作流的资源类型。

   1. 使用**目标**列表选择设置目标资源的方式。

      1. 如果选择使用参数值将资源设置为目标，请输入您在**输入参数**部分为参数选择的参数值。

      1. 如果选择使用 AWS Resource Groups 将资源设置为目标，请从**资源组**列表中选择组的名称。

      1. 如果选择使用标签将资源设置为目标，请在提供的字段中输入标签键和（可选）标签值。选择**添加**。

      1. 如果要在当前 AWS 账户 和 AWS 区域 中的所有实例上运行自动化运行手册，则选择**所有实例**。

1. 在**输入参数** 部分中，指定所需的输入。或者，您也可以从 **AutomationAssumeRole** 列表中选择一个 IAM 服务角色。
**注意**  
您可能不需要选择**输入参数**部分中的某些选项。原因是您使用标签或资源组将多个资源设置为目标。例如，如果选择了 `AWS-RestartEC2Instance` 运行手册，则无需在**输入参数** 部分中指定或选择实例 ID。自动化执行过程使用您指定的标签资源组查找要重新启动的实例。

1. 使用**速率控制**部分中的选项限制可在每个账户-区域对中运行自动化的 AWS 资源的数量。

   在**并发**部分中，选择一个选项：
   + 选择**目标**，以输入可同时运行自动化工作流目标的绝对数量。
   + 选择**百分比**，以输入可同时运行自动化工作流的目标集的百分比。

1. 在**错误阈值**部分中，选择一个选项：
   + 选择**错误**，以输入自动化停止将工作流程发送到其他资源之前允许的错误的绝对数量。
   + 选择**百分比**，以输入自动化停止将工作流程发送到其他资源之前允许的错误的百分比。

1. （可选）选择一个 CloudWatch 警报以应用于您的自动化进行监控。要将 CloudWatch 警报附加到自动化，启动自动化的 IAM 主体必须具有 `iam:createServiceLinkedRole` 操作的权限。有关 CloudWatch 警报的更多信息，请参阅[使用 Amazon CloudWatch 警报](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)。请注意，如果您的警报激活，自动化将停止。如果使用 AWS CloudTrail，您将在跟踪中看到 API 调用。

1. 选择**执行**。

要查看由速率控制自动化启动的自动化程序，请在导航窗格中，选择自动化，然后选择**显示子自动化程序**。

自动化执行完成后，您可以使用相同或修改后的参数重新运行该执行。有关更多信息，请参阅 [重新运行自动化执行](automation-rerun-executions.md)。

## 运行具有目标和速率控制的自动化（命令行）
<a name="scale-cli"></a>

以下过程介绍了如何使用 AWS CLI（在 Linux 或 Windows 上）或 AWS Tools for PowerShell 运行具有目标和速率控制的自动化。

**运行具有目标和速率控制的自动化**

1. 安装并配置 AWS CLI 或 AWS Tools for PowerShell（如果尚未执行该操作）。

   有关信息，请参阅[安装或更新 AWS CLI 的最新版本](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)以及[安装 AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html)。

1. 运行以下命令以查看文档列表。

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

   ```
   aws ssm list-documents
   ```

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

   ```
   aws ssm list-documents
   ```

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

   ```
   Get-SSMDocumentList
   ```

------

   记下要使用的运行手册的名称。

1. 运行以下命令以查看有关运行手册的详细信息。用您想要查看其详细信息的运行手册的名称替换 {{runbook name}}。同时，记下要用于 `--target-parameter-name` 选项的参数名称（例如 `InstanceId`）。此参数确定在其上运行自动化的资源的类型。

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

   ```
   aws ssm describe-document \
       --name {{runbook name}}
   ```

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

   ```
   aws ssm describe-document ^
       --name {{runbook name}}
   ```

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

   ```
   Get-SSMDocumentDescription `
       -Name {{runbook name}}
   ```

------

1. 创建一个要运行的使用目标和速率控制选项的命令。将每个{{示例资源占位符}}替换为您自己的信息。

   *使用标签设置目标*

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

   ```
   aws ssm start-automation-execution \
       --document-name {{runbook name}} \
       --targets Key=tag:{{key name}},Values={{value}} \
       --target-parameter-name {{parameter name}} \
       --parameters "{{input parameter name}}={{input parameter value}},{{input parameter 2 name}}={{input parameter 2 value}}" \
       --max-concurrency {{10}} \
       --max-errors {{25%}}
   ```

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

   ```
   aws ssm start-automation-execution ^
       --document-name {{runbook name}} ^
       --targets Key=tag:{{key name}},Values={{value}} ^
       --target-parameter-name {{parameter name}} ^
       --parameters "{{input parameter name}}={{input parameter value}},{{input parameter 2 name}}={{input parameter 2 value}}" ^
       --max-concurrency {{10}} ^
       --max-errors {{25%}}
   ```

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

   ```
   $Targets = New-Object Amazon.SimpleSystemsManagement.Model.Target
   $Targets.Key = "tag:{{key name}}"
   $Targets.Values = "{{value}}"
   
   Start-SSMAutomationExecution `
       DocumentName "{{runbook name}}" `
       -Targets $Targets `
       -TargetParameterName "{{parameter name}}" `
       -Parameter @{"{{input parameter name}}"="{{input parameter value}}";"{{input parameter 2 name}}"="{{input parameter 2 value}}"} `
       -MaxConcurrency "{{10}}" `
       -MaxError "{{25%}}"
   ```

------

   *使用参数值设置目标*

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

   ```
   aws ssm start-automation-execution \
       --document-name {{runbook name}} \
       --targets Key=ParameterValues,Values={{value}},{{value 2}},{{value 3}} \
       --target-parameter-name {{parameter name}} \
       --parameters "{{input parameter name}}={{input parameter value}}" \
       --max-concurrency {{10}} \
       --max-errors {{25%}}
   ```

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

   ```
   aws ssm start-automation-execution ^
       --document-name {{runbook name}} ^
       --targets Key=ParameterValues,Values={{value}},{{value 2}},{{value 3}} ^
       --target-parameter-name {{parameter name}} ^
       --parameters "{{input parameter name}}={{input parameter value}}" ^
       --max-concurrency {{10}} ^
       --max-errors {{25%}}
   ```

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

   ```
   $Targets = New-Object Amazon.SimpleSystemsManagement.Model.Target
   $Targets.Key = "ParameterValues"
   $Targets.Values = "{{value}}","{{value 2}}","{{value 3}}"
   
   Start-SSMAutomationExecution `
       -DocumentName "{{runbook name}}" `
       -Targets $Targets `
       -TargetParameterName "{{parameter name}}" `
       -Parameter @{"{{input parameter name}}"="{{input parameter value}}"} `
       -MaxConcurrency "{{10}}" `
       -MaxError "{{25%}}"
   ```

------

   *使用 AWS Resource Groups 设置目标*

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

   ```
   aws ssm start-automation-execution \
       --document-name {{runbook name}} \
       --targets Key=ResourceGroup,Values={{Resource group nname}} \
       --target-parameter-name {{parameter name}} \
       --parameters "{{input parameter name}}={{input parameter value}}" \
       --max-concurrency {{10}} \
       --max-errors {{25%}}
   ```

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

   ```
   aws ssm start-automation-execution ^
       --document-name {{runbook name}} ^
       --targets Key=ResourceGroup,Values={{Resource group name}} ^
       --target-parameter-name {{parameter name}} ^
       --parameters "{{input parameter name}}={{input parameter value}}" ^
       --max-concurrency {{10}} ^
       --max-errors {{25%}}
   ```

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

   ```
   $Targets = New-Object Amazon.SimpleSystemsManagement.Model.Target
   $Targets.Key = "ResourceGroup"
   $Targets.Values = "{{Resource group name}}"
   
   Start-SSMAutomationExecution `
       -DocumentName "{{runbook name}}" `
       -Targets $Targets `
       -TargetParameterName "{{parameter name}}" `
       -Parameter @{"{{input parameter name}}"="{{input parameter value}}"} `
       -MaxConcurrency "{{10}}" `
       -MaxError "{{25%}}"
   ```

------

   *将当前 AWS 账户 和 AWS 区域 中的所有 Amazon EC2 实例设置为目标*

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

   ```
   aws ssm start-automation-execution \
       --document-name {{runbook name}} \
       --targets "Key=AWS::EC2::Instance,Values=*"  \
       --target-parameter-name instanceId \
       --parameters "{{input parameter name}}={{input parameter value}}" \
       --max-concurrency {{10}} \
       --max-errors {{25%}}
   ```

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

   ```
   aws ssm start-automation-execution ^
       --document-name {{runbook name}} ^
       --targets Key=AWS::EC2::Instance,Values=* ^
       --target-parameter-name instanceId ^
       --parameters "{{input parameter name}}={{input parameter value}}" ^
       --max-concurrency {{10}} ^
       --max-errors {{25%}}
   ```

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

   ```
   $Targets = New-Object Amazon.SimpleSystemsManagement.Model.Target
   $Targets.Key = "AWS::EC2::Instance"
   $Targets.Values = "*"
   
   Start-SSMAutomationExecution `
       -DocumentName "{{runbook name}}" `
       -Targets $Targets `
       -TargetParameterName "instanceId" `
       -Parameter @{"{{input parameter name}}"="{{input parameter value}}"} `
       -MaxConcurrency "{{10}}" `
       -MaxError "{{25%}}"
   ```

------

   该命令将会返回执行 ID。请将该 ID 复制到剪贴板。您可以使用此 ID 查看自动化的状态。

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

   ```
   {
       "AutomationExecutionId": "a4a3c0e9-7efd-462a-8594-01234EXAMPLE"
   }
   ```

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

   ```
   {
       "AutomationExecutionId": "a4a3c0e9-7efd-462a-8594-01234EXAMPLE"
   }
   ```

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

   ```
   a4a3c0e9-7efd-462a-8594-01234EXAMPLE
   ```

------

1. 运行以下命令以查看自动化。将每个 {{automation execution ID}} 替换为您自己的信息。

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

   ```
   aws ssm describe-automation-executions \
       --filter Key=ExecutionId,Values={{automation execution ID}}
   ```

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

   ```
   aws ssm describe-automation-executions ^
       --filter Key=ExecutionId,Values={{automation execution ID}}
   ```

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

   ```
   Get-SSMAutomationExecutionList | `
       Where {$_.AutomationExecutionId -eq "{{automation execution ID}}"}
   ```

------

1. 运行以下命令以查看有关自动化进展的详细信息。将每个 {{automation execution ID}} 替换为您自己的信息。

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

   ```
   aws ssm get-automation-execution \
       --automation-execution-id {{automation execution ID}}
   ```

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

   ```
   aws ssm get-automation-execution ^
       --automation-execution-id {{automation execution ID}}
   ```

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

   ```
   Get-SSMAutomationExecution `
       -AutomationExecutionId {{automation execution ID}}
   ```

------

   系统将返回类似于以下内容的信息。

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

   ```
   {
       "AutomationExecution": {
           "StepExecutionsTruncated": false,
           "AutomationExecutionStatus": "Success",
           "MaxConcurrency": "1",
           "Parameters": {},
           "MaxErrors": "1",
           "Outputs": {},
           "DocumentName": "AWS-StopEC2Instance",
           "AutomationExecutionId": "a4a3c0e9-7efd-462a-8594-01234EXAMPLE",
           "ResolvedTargets": {
               "ParameterValues": [
                   "i-02573cafcfEXAMPLE"
               ],
               "Truncated": false
           },
           "ExecutionEndTime": 1564681619.915,
           "Targets": [
               {
                   "Values": [
                       "DEV"
                   ],
                   "Key": "tag:ENV"
               }
           ],
           "DocumentVersion": "1",
           "ExecutionStartTime": 1564681576.09,
           "ExecutedBy": "arn:aws:sts::123456789012:assumed-role/Administrator/Admin",
           "StepExecutions": [
               {
                   "Inputs": {
                       "InstanceId": "i-02573cafcfEXAMPLE"
                   },
                   "Outputs": {},
                   "StepName": "i-02573cafcfEXAMPLE",
                   "ExecutionEndTime": 1564681619.093,
                   "StepExecutionId": "86c7b811-3896-4b78-b897-01234EXAMPLE",
                   "ExecutionStartTime": 1564681576.836,
                   "Action": "aws:executeAutomation",
                   "StepStatus": "Success"
               }
           ],
           "TargetParameterName": "InstanceId",
           "Mode": "Auto"
       }
   }
   ```

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

   ```
   {
       "AutomationExecution": {
           "StepExecutionsTruncated": false,
           "AutomationExecutionStatus": "Success",
           "MaxConcurrency": "1",
           "Parameters": {},
           "MaxErrors": "1",
           "Outputs": {},
           "DocumentName": "AWS-StopEC2Instance",
           "AutomationExecutionId": "a4a3c0e9-7efd-462a-8594-01234EXAMPLE",
           "ResolvedTargets": {
               "ParameterValues": [
                   "i-02573cafcfEXAMPLE"
               ],
               "Truncated": false
           },
           "ExecutionEndTime": 1564681619.915,
           "Targets": [
               {
                   "Values": [
                       "DEV"
                   ],
                   "Key": "tag:ENV"
               }
           ],
           "DocumentVersion": "1",
           "ExecutionStartTime": 1564681576.09,
           "ExecutedBy": "arn:aws:sts::123456789012:assumed-role/Administrator/Admin",
           "StepExecutions": [
               {
                   "Inputs": {
                       "InstanceId": "i-02573cafcfEXAMPLE"
                   },
                   "Outputs": {},
                   "StepName": "i-02573cafcfEXAMPLE",
                   "ExecutionEndTime": 1564681619.093,
                   "StepExecutionId": "86c7b811-3896-4b78-b897-01234EXAMPLE",
                   "ExecutionStartTime": 1564681576.836,
                   "Action": "aws:executeAutomation",
                   "StepStatus": "Success"
               }
           ],
           "TargetParameterName": "InstanceId",
           "Mode": "Auto"
       }
   }
   ```

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

   ```
   AutomationExecutionId       : a4a3c0e9-7efd-462a-8594-01234EXAMPLE
   AutomationExecutionStatus   : Success
   CurrentAction               : 
   CurrentStepName             : 
   DocumentName                : AWS-StopEC2Instance
   DocumentVersion             : 1
   ExecutedBy                  : arn:aws:sts::123456789012:assumed-role/Administrator/Admin
   ExecutionEndTime            : 8/1/2019 5:46:59 PM
   ExecutionStartTime          : 8/1/2019 5:46:16 PM
   FailureMessage              : 
   MaxConcurrency              : 1
   MaxErrors                   : 1
   Mode                        : Auto
   Outputs                     : {}
   Parameters                  : {}
   ParentAutomationExecutionId : 
   ProgressCounters            : 
   ResolvedTargets             : Amazon.SimpleSystemsManagement.Model.ResolvedTargets
   StepExecutions              : {i-02573cafcfEXAMPLE}
   StepExecutionsTruncated     : False
   Target                      : 
   TargetLocations             : {}
   TargetMaps                  : {}
   TargetParameterName         : InstanceId
   Targets                     : {tag:Name}
   ```

------
**注意**  
您也可以在控制台中监控自动化的状态。在**自动化执行**列表中，请选择您刚才运行的自动化，然后选择**执行步骤**选项卡。该选项卡显示自动化操作的状态。