

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

# 注册不含目标的维护时段任务


对于您创建的每个维护时段，您可以指定要在维护时段运行时执行的一个或多个任务。在大多数情况下，您必须指定要在其上运行任务的资源或目标。但是，在某些情况下，无需在任务中明确指定目标。

必须为维护时段 Systems Manager Run Command 类型任务指定一个或多个目标。根据任务的性质，目标对于其他维护时段任务类型（Systems Manager 自动化、AWS Lambda 和 AWS Step Functions）是可选的。

对于 Lambda 和 Step Functions 任务类型，是否需要目标取决于您创建的函数或状态机的内容。

**注意**  
当任务注册了目标时，Automation、AWS Lambda 和 AWS Step Functions 任务会从资源组和标签解析目标，并为每个已解析的资源发送一次调用，这会导致多次任务调用。但是，举例来说，您只想对在包含多个实例的资源组中注册的 Lambda 任务进行一次调用。在这种情况下，如果您正在使用AWS 管理控制台，请在**注册 Lambda 任务**或**编辑 Lambda 任务**页面中选择**任务目标不是必需的**选项。如果使用 AWS CLI 命令，则在运行 [https://docs.aws.amazon.com/cli/latest/reference/ssm/register-task-with-maintenance-window.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/register-task-with-maintenance-window.html) 命令或 [https://docs.aws.amazon.com/cli/latest/reference/ssm/update-maintenance-window-task.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/update-maintenance-window-task.html) 命令时，请勿使用 `--targets` 参数指定目标。

在许多情况下，您无需为自动化任务明确指定目标。例如，假设您要创建 自动化 类型的任务，以使用 `AWS-UpdateLinuxAmi` 运行手册为 Linux 更新 Amazon Machine Image (AMI)。在该任务运行时，已使用最新可用的 Linux 分发版本的程序包和 Amazon 软件更新了 AMI。从 AMI 创建的新实例已经安装了这些更新。由于要更新的 AMI 的 ID 是在运行手册的输入参数中指定的，因此无需在维护时段任务中再次指定目标。

同样，假设您正在使用 AWS Command Line Interface (AWS CLI) 注册使用 `AWS-RestartEC2Instance` 运行手册的维护时段 Automation 任务。由于要重启的节点是在 `--task-invocation-parameters` 参数中指定，您也无需指定 `--targets` 选项。

**注意**  
对于没有指定目标的维护时段任务，您无法为 `--max-errors` 和 `--max-concurrency` 提供值。作为替代方式，系统会插入一个占位符值 `1`，该值可能会在响应诸如 [https://docs.aws.amazon.com/cli/latest/reference/ssm/describe-maintenance-window-tasks.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/describe-maintenance-window-tasks.html) 和 [https://docs.aws.amazon.com/cli/latest/reference/ssm/get-maintenance-window-task.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/get-maintenance-window-task.html) 等命令时发出报告。这些值不会影响任务的运行，并且可以忽略。

以下示例演示了为无目标维护时段任务省略 `--targets`、`--max-errors` 和 `--max-concurrency` 选项的情形。

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

```
aws ssm register-task-with-maintenance-window \
    --window-id "mw-ab12cd34eEXAMPLE" \
    --service-role-arn "arn:aws:iam::123456789012:role/MaintenanceWindowAndAutomationRole" \
    --task-type "AUTOMATION" \
    --name "RestartInstanceWithoutTarget" \
    --task-arn "AWS-RestartEC2Instance" \
    --task-invocation-parameters "{\"Automation\":{\"Parameters\":{\"InstanceId\":[\"i-02573cafcfEXAMPLE\"]}}}" \
    --priority 10
```

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

```
aws ssm register-task-with-maintenance-window ^
    --window-id "mw-ab12cd34eEXAMPLE" ^
    --service-role-arn "arn:aws:iam::123456789012:role/MaintenanceWindowAndAutomationRole" ^
    --task-type "AUTOMATION" ^
    --name "RestartInstanceWithoutTarget" ^
    --task-arn "AWS-RestartEC2Instance" ^
    --task-invocation-parameters "{\"Automation\":{\"Parameters\":{\"InstanceId\":[\"i-02573cafcfEXAMPLE\"]}}}" ^
    --priority 10
```

------

**注意**  
对于 2020 年 12 月 23 日之前注册的维护时段任务：如果您为任务指定了多个目标，但不再需要一个目标，则可以更新该任务，以使用 Systems Manager 控制台或 [https://docs.aws.amazon.com/cli/latest/reference/ssm/update-maintenance-window-task.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/update-maintenance-window-task.html) AWS CLI 命令删除目标。

**更多信息**  
+ [错误消息：“Maintenance window tasks without targets don't support MaxConcurrency values (没有目标的维护时段任务不支持 MaxConcurrency 值)”和“Maintenance window tasks without targets don't support MaxErrors values (没有目标的维护时段任务不支持 MaxErrors 值)”](troubleshooting-maintenance-windows.md#maxconcurrency-maxerrors-not-supported)