

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

# 步骤 3：使用 AWS CLI 向维护时段注册任务
<a name="mw-cli-tutorial-tasks"></a>

在教程的此步骤中，您将注册 AWS Systems Manager Run Command 任务，该任务将在适用于 Linux 的 Amazon Elastic Compute Cloud (Amazon EC2) 实例上运行 `df` 命令。此标准 Linux 命令的结果显示实例的磁盘文件系统上的空闲空间数量和已用空间数量。

–或者–

如果您设定的目标是适用于 Windows Server 而不是 Linux 的 Amazon EC2 实例，请将以下命令中的 **df** 替换为 **ipconfig**。此命令的输出列出了有关目标实例上适配器的 IP 地址、子网掩码和默认网关等详细信息。

当您准备好注册其他任务类型，或使用更多可用 Systems Manager Run Command 选项时，请参阅 [示例：向维护时段注册任务](mw-cli-register-tasks-examples.md)。我们在这里提供了有关全部四种任务类型的更多信息，以及它们最重要的一些选项，以帮助您针对更广泛的真实情况制定计划。

**向维护时段注册任务**

1. 在本地计算机上运行以下命令。将每个*示例资源占位符*替换为您自己的信息。从本地 Windows 计算机运行的版本包含转义字符 (“/”)，您需要从命令行工具运行命令。

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

   ```
   aws ssm register-task-with-maintenance-window \
       --window-id mw-0c50858d01EXAMPLE \
       --task-arn "AWS-RunShellScript" \
       --max-concurrency 1 --max-errors 1 \
       --priority 10 \
       --targets "Key=InstanceIds,Values=i-0471e04240EXAMPLE" \
       --task-type "RUN_COMMAND" \
       --task-invocation-parameters '{"RunCommand":{"Parameters":{"commands":["df"]}}}'
   ```

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

   ```
   aws ssm register-task-with-maintenance-window ^
       --window-id mw-0c50858d01EXAMPLE ^
       --task-arn "AWS-RunShellScript" ^
       --max-concurrency 1 --max-errors 1 ^
       --priority 10 ^
       --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" ^
       --task-type "RUN_COMMAND" ^
       --task-invocation-parameters={\"RunCommand\":{\"Parameters\":{\"commands\":[\"df\"]}}}
   ```

------

   系统返回类似于下文的信息：

   ```
   {
       "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE"
   }
   ```

1. 现在，运行以下命令查看有关您创建的维护时段任务的详细信息。

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

   ```
   aws ssm describe-maintenance-window-tasks \
       --window-id mw-0c50858d01EXAMPLE
   ```

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

   ```
   aws ssm describe-maintenance-window-tasks ^
       --window-id mw-0c50858d01EXAMPLE
   ```

------

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

   ```
   {
       "Tasks": [
           {
               "WindowId": "mw-0c50858d01EXAMPLE",
               "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
               "TaskArn": "AWS-RunShellScript",
               "Type": "RUN_COMMAND",
               "Targets": [
                   {
                       "Key": "InstanceIds",
                       "Values": [
                           "i-02573cafcfEXAMPLE"
                       ]
                   }
               ],
               "TaskParameters": {},
               "Priority": 10,
               "ServiceRoleArn": "arn:aws:iam::123456789012:role/MyMaintenanceWindowServiceRole",
               "MaxConcurrency": "1",
               "MaxErrors": "1"
           }
       ]
   }
   ```

1. 请耐心等待，直到有足够的时间根据您在[步骤 1：使用 AWS CLI 创建维护时段](mw-cli-tutorial-create-mw.md) 中指定的计划运行任务。例如，如果您指定了 **--schedule "rate(5 minutes)"**，则等待五分钟。然后，运行以下命令来查看此任务所进行的任何执行的相关信息。

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

   ```
   aws ssm describe-maintenance-window-executions \
       --window-id mw-0c50858d01EXAMPLE
   ```

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

   ```
   aws ssm describe-maintenance-window-executions ^
       --window-id mw-0c50858d01EXAMPLE
   ```

------

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

   ```
   {
       "WindowExecutions": [
           {
               "WindowId": "mw-0c50858d01EXAMPLE",
               "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
               "Status": "SUCCESS",
               "StartTime": 1557593493.096,
               "EndTime": 1557593498.611
           }
       ]
   }
   ```

**提示**  
任务成功运行后，您可以降低维护时段运行的速率。例如，运行以下命令以将频率减少为每周一次。将 *mw-0c50858d01EXAMPLE* 替换为您自己的信息。  

```
aws ssm update-maintenance-window \
    --window-id mw-0c50858d01EXAMPLE \
    --schedule "rate(7 days)"
```

```
aws ssm update-maintenance-window ^
    --window-id mw-0c50858d01EXAMPLE ^
    --schedule "rate(7 days)"
```
有关管理维护时段计划的信息，请参阅 [参考：适用于 Systems Manager 的 Cron 和 Rate 表达式](reference-cron-and-rate-expressions.md) 和 [维护时段计划和活动期间选项](maintenance-windows-schedule-options.md)。  
有关使用 AWS Command Line Interface (AWS CLI) 修改维护时段的信息，请参阅 [教程：使用 AWS CLI 更新维护时段](maintenance-windows-cli-tutorials-update.md)。

有关运行 AWS CLI 命令以查看有关维护时段任务及其执行详细信息的练习，请转到[教程：查看有关任务和使用 AWS CLI 执行任务的信息](mw-cli-tutorial-task-info.md)。

**访问教程命令输出**  
使用 AWS CLI 查看与您的维护时段任务执行相关联的 Run Command 命令的*输出*，不在本教程的讨论范围内。

不过，您可以使用 AWS CLI 查看此数据。（您还可以在 Systems Manager 控制台中或存储在 Amazon Simple Storage Service (Amazon S3) 存储桶内的日志文件中（如果您已配置维护时段将命令输出存储在其中）查看输出。） 您会看到，适用于 Linux 的 Amazon EC2 实例上 **df** 命令的输出类似于下文：

```
Filesystem 1K-blocks Used Available Use% Mounted on

devtmpfs 485716 0 485716 0% /dev

tmpfs 503624 0 503624 0% /dev/shm

tmpfs 503624 328 503296 1% /run

tmpfs 503624 0 503624 0% /sys/fs/cgroup

/dev/xvda1 8376300 1464160 6912140 18% /
```

Windows Server 的 EC2 实例上 **ipconfig** 命令的输出类似于下文：

```
Windows IP Configuration


Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . : example.com
   IPv4 Address. . . . . . . . . . . : 10.24.34.0/23
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . : 0.0.0.0

Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : abc1.wa.example.net

Wireless LAN adapter Local Area Connection* 1:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::100b:c234:66d6:d24f%4
   IPv4 Address. . . . . . . . . . . : 192.0.2.0
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.0.2.0

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
```

# 示例：向维护时段注册任务
<a name="mw-cli-register-tasks-examples"></a>

您可以使用 AWS Command Line Interface（AWS CLI）将 Run Command（AWS Systems Manager 中的一项工具）中的任务注册到维护时段，如[向维护时段注册任务](mw-cli-tutorial-tasks.md)中所示。您还可以为 Systems Manager 自动化 工作流、AWS Lambda 函数和 AWS Step Functions 任务注册任务，如本主题后面的内容所示。

**注意**  
为维护时段 Run Command 类型任务指定一个或多个目标。根据任务的不同，目标对于其他维护时段任务类型（自动化、AWS Lambda 和 AWS Step Functions）是可选的。有关运行未指定目标的任务的更多信息，请参阅 [注册不含目标的维护时段任务](maintenance-windows-targetless-tasks.md)。

在本主题中，我们提供的示例演示了如何使用 AWS Command Line Interface (AWS CLI) 命令 `register-task-with-maintenance-window`，分别将四种支持的任务类型注册到维护时段。这些示例仅用于演示目的，不过您可以修改它们以创建工作任务注册命令。

**使用 --cli-input-json 选项**  
为了更好地管理任务选项，您可以使用命令选项 `--cli-input-json`，其选项值在 JSON 文件中引用。

要使用我们在下列示例中提供的示例 JSON 文件内容，请在您本地计算机上执行以下操作：

1. 创建一个文件，采用类似于 `MyRunCommandTask.json`、`MyAutomationTask.json` 或其他您偏好的名称。

1. 将 JSON 示例内容复制到该文件中。

1. 为您的任务注册修改文件内容，然后保存该文件。

1. 在存储文件的同一个目录中，运行以下命令：用您的文件名替换 *MyFile.json*。

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

   ```
   aws ssm register-task-with-maintenance-window \
       --cli-input-json file://MyFile.json
   ```

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

   ```
   aws ssm register-task-with-maintenance-window ^
       --cli-input-json file://MyFile.json
   ```

------

**维护时段任务中的伪参数**  
在某些示例中，我们使用*伪参数* 作为将 ID 信息传递到您任务的方法。例如，`{{TARGET_ID}}` 和 `{{RESOURCE_ID}}` 可用于将 AWS 资源的 ID 传递到 自动化、Lambda 和 Step Functions 任务。有关 `--task-invocation-parameters` 内容中伪参数的更多信息，请参阅 [注册维护时段任务时使用伪参数](maintenance-window-tasks-pseudo-parameters.md)。

**更多信息**  
+ [register-task-with-maintenance-windows 命令的参数选项](mw-cli-task-options.md).
+ 《AWS CLI Command Reference》**中的 [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)。
+ **《AWS Systems Manager API 参考》中的 [https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_RegisterTaskWithMaintenanceWindow.html](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_RegisterTaskWithMaintenanceWindow.html)

## 任务注册示例
<a name="task-examples"></a>

以下部分提供了一个示例 AWS CLI 命令，用于注册支持的任务类型和可与 `--cli-input-json` 选项一起使用的 JSON 示例。

### 注册 Systems Manager Run Command 任务
<a name="register-tasks-tutorial-run-command"></a>

以下示例演示了如何使用 AWS CLI 将 Systems Manager Run Command 任务注册到维护时段。

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

```
aws ssm register-task-with-maintenance-window \
    --window-id mw-0c50858d01EXAMPLE \
    --task-arn "AWS-RunShellScript" \
    --max-concurrency 1 --max-errors 1 --priority 10 \
    --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" \
    --task-type "RUN_COMMAND" \
    --task-invocation-parameters '{"RunCommand":{"Parameters":{"commands":["df"]}}}'
```

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

```
aws ssm register-task-with-maintenance-window ^
    --window-id mw-0c50858d01EXAMPLE ^
    --task-arn "AWS-RunShellScript" ^
    --max-concurrency 1 --max-errors 1 --priority 10 ^
    --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" ^
    --task-type "RUN_COMMAND" ^
    --task-invocation-parameters "{\"RunCommand\":{\"Parameters\":{\"commands\":[\"df\"]}}}"
```

------

**用于 `--cli-input-json` 文件选项的 JSON 内容：**

```
{
    "TaskType": "RUN_COMMAND",
    "WindowId": "mw-0c50858d01EXAMPLE",
    "Description": "My Run Command task to update SSM Agent on an instance",
    "MaxConcurrency": "1",
    "MaxErrors": "1",
    "Name": "My-Run-Command-Task",
    "Priority": 10,
    "Targets": [
        {
            "Key": "WindowTargetIds",
            "Values": [
                "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
            ]
        }
    ],
    "TaskArn": "AWS-UpdateSSMAgent",
    "TaskInvocationParameters": {
        "RunCommand": {
            "Comment": "A TaskInvocationParameters test comment",
            "NotificationConfig": {
                "NotificationArn": "arn:aws:sns:region:123456789012:my-sns-topic-name",
                "NotificationEvents": [
                    "All"
                ],
                "NotificationType": "Invocation"
            },
            "OutputS3BucketName": "amzn-s3-demo-bucket",
            "OutputS3KeyPrefix": "S3-PREFIX",
            "TimeoutSeconds": 3600
        }
    }
}
```

### 注册 Systems Manager 自动化 任务
<a name="register-tasks-tutorial-automation"></a>

以下示例演示了如何使用 AWS CLI 将 Systems Manager 自动化 任务注册到维护时段：

**AWS CLI 命令：**

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

```
aws ssm register-task-with-maintenance-window \
    --window-id "mw-0c50858d01EXAMPLE" \
    --task-arn "AWS-RestartEC2Instance" \
    --service-role-arn arn:aws:iam::123456789012:role/MyMaintenanceWindowServiceRole \
    --task-type AUTOMATION \
    --task-invocation-parameters "Automation={DocumentVersion=5,Parameters={InstanceId='{{RESOURCE_ID}}'}}" \
    --priority 0 --name "My-Restart-EC2-Instances-Automation-Task" \
    --description "Automation task to restart EC2 instances"
```

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

```
aws ssm register-task-with-maintenance-window ^
    --window-id "mw-0c50858d01EXAMPLE" ^
    --task-arn "AWS-RestartEC2Instance" ^
    --service-role-arn arn:aws:iam::123456789012:role/MyMaintenanceWindowServiceRole ^
    --task-type AUTOMATION ^
    --task-invocation-parameters "Automation={DocumentVersion=5,Parameters={InstanceId='{{TARGET_ID}}'}}" ^
    --priority 0 --name "My-Restart-EC2-Instances-Automation-Task" ^
    --description "Automation task to restart EC2 instances"
```

------

**用于 `--cli-input-json` 文件选项的 JSON 内容：**

```
{
    "WindowId": "mw-0c50858d01EXAMPLE",
        "TaskArn": "AWS-PatchInstanceWithRollback",
    "TaskType": "AUTOMATION","TaskInvocationParameters": {
        "Automation": {
            "DocumentVersion": "1",
            "Parameters": {
                "instanceId": [
                    "{{RESOURCE_ID}}"
                ]
            }
        }
    }
}
```

### 注册 AWS Lambda 任务
<a name="register-tasks-tutorial-lambda"></a>

以下示例演示了如何使用 AWS CLI 将 Lambda 函数任务注册到维护时段。

对于这些示例，创建 Lambda 函数的用户将其命名为 `SSMrestart-my-instances`，并创建了名为 `instanceId` 和 `targetType` 的两个参数。

**重要**  
Maintenance Windows 的 IAM policy 要求您将前缀 `SSM` 添加到 Lambda 函数（或别名）名称。继续注册此类型的任务之前，请在 AWS Lambda 中更新其名称，以包含 `SSM`。例如，如果您的 Lambda 函数名称为 `MyLambdaFunction`，请将其更改为 `SSMMyLambdaFunction`。

**AWS CLI 命令：**

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

**重要**  
如果您使用的是版本 2 的 AWS CLI，并且您的 Lambda 有效负载没有进行 base64 编码，则您必须在以下命令中包含选项 `--cli-binary-format raw-in-base64-out`。`cli_binary_format` 选项仅在版本 2 中可用。有关此设置和其他 AWS CLI `config` 文件设置的信息，请参阅 *AWS Command Line Interface 用户指南*中的[受支持的 `config` 文件设置](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-settings)。

```
aws ssm register-task-with-maintenance-window \
    --window-id "mw-0c50858d01EXAMPLE" \
    --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \
    --priority 2 --max-concurrency 10 --max-errors 5 --name "My-Lambda-Example" \
    --description "A description for my LAMBDA example task" --task-type "LAMBDA" \
    --task-arn "arn:aws:lambda:region:123456789012:function:serverlessrepo-SSMrestart-my-instances-C4JF9EXAMPLE" \
    --task-invocation-parameters '{"Lambda":{"Payload":"{\"InstanceId\":\"{{RESOURCE_ID}}\",\"targetType\":\"{{TARGET_TYPE}}\"}","Qualifier": "$LATEST"}}'
```

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

**重要**  
如果您使用的是版本 2 的 AWS CLI，并且您的 Lambda 有效负载没有进行 base64 编码，则您必须在以下命令中包含选项 `--cli-binary-format raw-in-base64-out`。`cli_binary_format` 选项仅在版本 2 中可用。有关此设置和其他 AWS CLI `config` 文件设置的信息，请参阅 *AWS Command Line Interface 用户指南*中的[受支持的 `config` 文件设置](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-settings)。

```
aws ssm register-task-with-maintenance-window `
    --window-id "mw-0c50858d01EXAMPLE" `
    --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" `
    --priority 2 --max-concurrency 10 --max-errors 5 --name "My-Lambda-Example" `
    --description "A description for my LAMBDA example task" --task-type "LAMBDA" `
    --task-arn "arn:aws:lambda:region:123456789012:function:serverlessrepo-SSMrestart-my-instances-C4JF9EXAMPLE" `
    --task-invocation-parameters '{\"Lambda\":{\"Payload\":\"{\\\"InstanceId\\\":\\\"{{RESOURCE_ID}}\\\",\\\"targetType\\\":\\\"{{TARGET_TYPE}}\\\"}\",\"Qualifier\": \"$LATEST\"}}'
```

------

**用于 `--cli-input-json` 文件选项的 JSON 内容：**

```
{
    "WindowId": "mw-0c50858d01EXAMPLE",
    "Targets": [
        {
            "Key": "WindowTargetIds",
            "Values": [
                "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
            ]
        }
    ],
    "TaskArn": "SSM_RestartMyInstances",
    "TaskType": "LAMBDA",
    "MaxConcurrency": "10",
    "MaxErrors": "10",
    "TaskInvocationParameters": {
        "Lambda": {
            "ClientContext": "ew0KICAi--truncated--0KIEXAMPLE",
            "Payload": "{ \"instanceId\": \"{{RESOURCE_ID}}\", \"targetType\": \"{{TARGET_TYPE}}\" }",
            "Qualifier": "$LATEST"
        }
    },
    "Name": "My-Lambda-Task",
    "Description": "A description for my LAMBDA task",
    "Priority": 5
}
```

### 注册 Step Functions 任务
<a name="register-tasks-tutorial-step-functions"></a>

以下示例演示了如何使用 AWS CLI 将 Step Functions 状态机任务注册到维护时段。

**注意**  
维护时段任务仅支持 Step Functions 标准状态机工作流。它们不支持快速状态机工作流。有关状态机工作流类型的信息，请参阅《AWS Step Functions 开发人员指南》**中的[标准与快速工作流](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-standard-vs-express.html)。

对于这些示例，创建 Step Functions 状态机的用户使用名为 `instanceId` 的参数创建名为 `SSMMyStateMachine` 的状态机。

**重要**  
Maintenance Windows 的 AWS Identity and Access Management （IAM）policy 要求您使用 `SSM` 作为 Step Functions 状态机名称的前缀。继续注册此类型的任务之前，您必须在 AWS Step Functions 中更新此名称以包括 `SSM`。例如，如果您的状态机名为 `MyStateMachine`，则将其更改为 `SSMMyStateMachine`。

**AWS CLI 命令：**

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

```
aws ssm register-task-with-maintenance-window \
    --window-id "mw-0c50858d01EXAMPLE" \
    --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" \
    --task-arn arn:aws:states:region:123456789012:stateMachine:SSMMyStateMachine-MggiqEXAMPLE \
    --task-type STEP_FUNCTIONS \
    --task-invocation-parameters '{"StepFunctions":{"Input":"{\"InstanceId\":\"{{RESOURCE_ID}}\"}", "Name":"{{INVOCATION_ID}}"}}' \
    --priority 0 --max-concurrency 10 --max-errors 5 \
    --name "My-Step-Functions-Task" --description "A description for my Step Functions task"
```

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

```
aws ssm register-task-with-maintenance-window `
    --window-id "mw-0c50858d01EXAMPLE" `
    --targets "Key=WindowTargetIds,Values=e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" `
    --task-arn arn:aws:states:region:123456789012:stateMachine:SSMMyStateMachine-MggiqEXAMPLE `
    --task-type STEP_FUNCTIONS `
    --task-invocation-parameters '{\"StepFunctions\":{\"Input\":\"{\\\"InstanceId\\\":\\\"{{RESOURCE_ID}}\\\"}\", \"Name\":\"{{INVOCATION_ID}}\"}}' `
    --priority 0 --max-concurrency 10 --max-errors 5 `
    --name "My-Step-Functions-Task" --description "A description for my Step Functions task"
```

------

**用于 `--cli-input-json` 文件选项的 JSON 内容：**

```
{
    "WindowId": "mw-0c50858d01EXAMPLE",
    "Targets": [
        {
            "Key": "WindowTargetIds",
            "Values": [
                "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE"
            ]
        }
    ],
    "TaskArn": "SSM_MyStateMachine",
    "TaskType": "STEP_FUNCTIONS",
    "MaxConcurrency": "10",
    "MaxErrors": "10",
    "TaskInvocationParameters": {
        "StepFunctions": {
            "Input": "{ \"instanceId\": \"{{TARGET_ID}}\" }",
            "Name": "{{INVOCATION_ID}}"
        }
    },
    "Name": "My-Step-Functions-Task",
    "Description": "A description for my Step Functions task",
    "Priority": 5
}
```

# register-task-with-maintenance-windows 命令的参数选项
<a name="mw-cli-task-options"></a>

**register-task-with-maintenance-window** 命令提供多个选项用于根据您的需求配置任务。其中一些任务为必需，一些为可选，还有一些仅适用于单个维护时段任务类型。

本主题提供了有关其中一些选项的信息，以帮助您使用本教程这一部分中的示例。有关所有命令选项的信息，请参阅 *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)**。

**命令选项：`--task-arn`**  
`--task-arn` 选项用于指定执行任务的资源。您指定的值取决于所要注册的任务类型，如下表中所述。


**维护时段任务的 TaskArn 格式**  

| 维护时段任务类型 | TaskArn 值 | 
| --- | --- | 
|  **`RUN_COMMAND`** 和 **`AUTOMATION`**  |  `TaskArn` 是 SSM 文档名称或 Amazon Resource Name (ARN)。例如： `AWS-RunBatchShellScript`  –或者– `arn:aws:ssm:region:111122223333:document/My-Document`.  | 
|  **`LAMBDA`**  |  `TaskArn` 是函数名称或 ARN。例如： `SSMMy-Lambda-Function` –或者– `arn:aws:lambda:region:111122223333:function:SSMMyLambdaFunction`.  Maintenance Windows 的 IAM policy 要求您将前缀 `SSM` 添加到 Lambda 函数（或别名）名称。继续注册此类型的任务之前，请在 AWS Lambda 中更新其名称，以包含 `SSM`。例如，如果您的 Lambda 函数名称为 `MyLambdaFunction`，请将其更改为 `SSMMyLambdaFunction`。   | 
|  **`STEP_FUNCTIONS`**  |  `TaskArn` 是状态机 ARN。例如： `arn:aws:states:us-east-2:111122223333:stateMachine:SSMMyStateMachine`.  维护时段的 IAM policy 要求您使用 `SSM` 作为 Step Functions 状态机名称的前缀。您应先注册此类型的任务，然后必须在 AWS Step Functions 中更新其名称以包含 `SSM`。例如，如果您的状态机名为 `MyStateMachine`，则将其更改为 `SSMMyStateMachine`。   | 

**命令选项：`--service-role-arn`**  
运行维护时段任务时 AWS Systems Manager 要代入的角色。

有关更多信息，请参阅 [设置 Maintenance Windows](setting-up-maintenance-windows.md)。

**命令选项：`--task-invocation-parameters`**  
`--task-invocation-parameters` 选项用于指定分别对于四种任务类型唯一的参数。四种任务类型分别支持的参数如下表中所述。

**注意**  
有关在 `--task-invocation-parameters` 内容中使用伪参数的信息，例如 \$1\$1TARGET\$1ID\$1\$1，请参阅[注册维护时段任务时使用伪参数](maintenance-window-tasks-pseudo-parameters.md)。

维护任务时段的任务调用参数选项


| 维护时段任务类型 | 可用参数  | 示例 | 
| --- | --- | --- | 
|  **`RUN_COMMAND`**  |  `Comment` `DocumentHash` `DocumentHashType` `NotificationConfig` `OutputS3BucketName` `OutPutS3KeyPrefix` `Parameters` `ServiceRoleArn` `TimeoutSeconds`  |  <pre>"TaskInvocationParameters": {<br />        "RunCommand": {<br />            "Comment": "My Run Command task comment",<br />            "DocumentHash": "6554ed3d--truncated--5EXAMPLE",<br />            "DocumentHashType": "Sha256",<br />            "NotificationConfig": {<br />                "NotificationArn": "arn:aws:sns:region:123456789012:my-sns-topic-name",<br />                "NotificationEvents": [<br />                    "FAILURE"<br />                ],<br />                "NotificationType": "Invocation"<br />            },<br />            "OutputS3BucketName": "amzn-s3-demo-bucket",<br />            "OutputS3KeyPrefix": "S3-PREFIX",<br />            "Parameters": {<br />                "commands": [<br />                    "Get-ChildItem$env: temp-Recurse|Remove-Item-Recurse-force"<br />                ]<br />            },<br />            "ServiceRoleArn": "arn:aws:iam::123456789012:role/MyMaintenanceWindowServiceRole",<br />            "TimeoutSeconds": 3600<br />        }<br />    }</pre>  | 
|  **`AUTOMATION`**  |  `DocumentVersion` `Parameters`  |  <pre>"TaskInvocationParameters": {<br />        "Automation": {<br />            "DocumentVersion": "3",<br />            "Parameters": {<br />                "instanceid": [<br />                    "{{TARGET_ID}}"<br />                ]<br />            }<br />        }<br />    }</pre>  | 
|  **`LAMBDA`**  |  `ClientContext` `Payload` `Qualifier`  |  <pre>"TaskInvocationParameters": {<br />        "Lambda": {<br />            "ClientContext": "ew0KICAi--truncated--0KIEXAMPLE",<br />            "Payload": "{ \"targetId\": \"{{TARGET_ID}}\", \"targetType\": \"{{TARGET_TYPE}}\" }",<br />            "Qualifier": "$LATEST"<br />        }<br />    }</pre>  | 
|  **`STEP_FUNCTIONS`**  |  `Input` `Name`  |  <pre>"TaskInvocationParameters": {<br />        "StepFunctions": {<br />            "Input": "{ \"targetId\": \"{{TARGET_ID}}\" }",<br />            "Name": "{{INVOCATION_ID}}"<br />        }<br />    }</pre>  | 