教程:查看有关维护时段的信息 (Amazon CLI) - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

教程:查看有关维护时段的信息 (Amazon CLI)

本教程包含的命令可帮助您更新维护时段、任务、执行和调用或获取相关信息。这些示例按命令进行组织,说明如何使用命令选项筛选要查看的详细信息类型。

在按照本教程中的步骤操作时,请将以斜体红色文本显示的值替换为您自己的选项和 ID。例如,请将维护时段 ID mw-0c50858d01EXAMPLE 和实例 ID i-02573cafcfEXAMPLE 替换为您创建的资源的 ID。

有关设置和配置 Amazon Command Line Interface (Amazon CLI) 的信息,请参阅安装、更新和卸载 Amazon CLI配置 Amazon CLI

'describe-maintenance-windows' 的示例

列出您的 Amazon Web Services 账户中的所有维护时段

运行以下命令。

aws ssm describe-maintenance-windows

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

{
   "WindowIdentities":[
      {
         "WindowId":"mw-0c50858d01EXAMPLE",
         "Name":"My-First-Maintenance-Window",
         "Enabled":true,
         "Duration":2,
         "Cutoff":0,
         "NextExecutionTime": "2019-05-18T17:01:01.137Z"        
      },
      {
         "WindowId":"mw-9a8b7c6d5eEXAMPLE",
         "Name":"My-Second-Maintenance-Window",
         "Enabled":true,
         "Duration":4,
         "Cutoff":1,
         "NextExecutionTime": "2019-05-30T03:30:00.137Z"        
      },
   ]
}
列出所有已启用的维护时段

运行以下命令。

aws ssm describe-maintenance-windows --filters "Key=Enabled,Values=true"

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

{
   "WindowIdentities":[
      {
         "WindowId":"mw-0c50858d01EXAMPLE",
         "Name":"My-First-Maintenance-Window",
         "Enabled":true,
         "Duration":2,
         "Cutoff":0,
         "NextExecutionTime": "2019-05-18T17:01:01.137Z"        
      },
      {
         "WindowId":"mw-9a8b7c6d5eEXAMPLE",
         "Name":"My-Second-Maintenance-Window",
         "Enabled":true,
         "Duration":4,
         "Cutoff":1,
         "NextExecutionTime": "2019-05-30T03:30:00.137Z"        
      },
   ]
}
列出所有已禁用的维护时段

运行以下命令。

aws ssm describe-maintenance-windows --filters "Key=Enabled,Values=false"

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

{
    "WindowIdentities": [
        {
            "WindowId": "mw-6e5c9d4b7cEXAMPLE",
            "Name": "My-Disabled-Maintenance-Window",
            "Enabled": false,
            "Duration": 2,
            "Cutoff": 1
        }
    ]
}
列出名称以特定前缀开头的所有维护时段

运行以下命令。

aws ssm describe-maintenance-windows --filters "Key=Name,Values=My"

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

{
    "WindowIdentities": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "Enabled": true,
            "Duration": 2,
            "Cutoff": 0,
            "NextExecutionTime": "2019-05-18T17:01:01.137Z"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "My-Second-Maintenance-Window",
            "Enabled": true,
            "Duration": 4,
            "Cutoff": 1,
            "NextExecutionTime": "2019-05-30T03:30:00.137Z"
        },
        {
            "WindowId": "mw-6e5c9d4b7cEXAMPLE",
            "Name": "My-Disabled-Maintenance-Window",
            "Enabled": false,
            "Duration": 2,
            "Cutoff": 1
        }
    ]
}

'describe-maintenance-window-targets' 的示例

显示匹配特定所有者信息值的维护时段的目标

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-targets \ --window-id "mw-6e5c9d4b7cEXAMPLE" \ --filters "Key=OwnerInformation,Values=CostCenter1"
Windows
aws ssm describe-maintenance-window-targets ^ --window-id "mw-6e5c9d4b7cEXAMPLE" ^ --filters "Key=OwnerInformation,Values=CostCenter1"
注意

支持的筛选条件键为 TypeWindowTargetIdOwnerInformation

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

{
    "Targets": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE",
            "ResourceType": "INSTANCE",
            "Targets": [
                {
                    "Key": "tag:Name",
                    "Values": [
                        "Production"
                    ]
                }
            ],
            "OwnerInformation": "CostCenter1",
            "Name": "Target1"
        }
    ]
}

'describe-maintenance-window-tasks' 的示例

显示调用 SSM 命令文档 AWS-RunPowerShellScript 的所有已注册任务

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-tasks \ --window-id "mw-0c50858d01EXAMPLE" \ --filters "Key=TaskArn,Values=AWS-RunPowerShellScript"
Windows
aws ssm describe-maintenance-window-tasks ^ --window-id "mw-0c50858d01EXAMPLE" ^ --filters "Key=TaskArn,Values=AWS-RunPowerShellScript"

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

{
   "Tasks":[
      {
         "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "driverquery.exe"
               ]
            }
         },
         "Priority":3,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"i-02573cafcfEXAMPLE",
               "TaskTargetType":"INSTANCE"
            }
         ]
      },
      {
         "ServiceRoleArn":"arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "ipconfig"
               ]
            }
         },
         "Priority":1,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"i-02573cafcfEXAMPLE",
               "TaskTargetType":"WINDOW_TARGET"
            }
         ]
      }
   ]
}
显示优先级为“3”的所有已注册任务

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-tasks \ --window-id "mw-9a8b7c6d5eEXAMPLE" \ --filters "Key=Priority,Values=3"
Windows
aws ssm describe-maintenance-window-tasks ^ --window-id "mw-9a8b7c6d5eEXAMPLE" ^ --filters "Key=Priority,Values=3"

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

{
   "Tasks":[
      {
         "ServiceRoleArn":"arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "driverquery.exe"
               ]
            }
         },
         "Priority":3,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"i-02573cafcfEXAMPLE",
               "TaskTargetType":"INSTANCE"
            }
         ]
      }
   ]
}
显示优先级为 1 且使用 Run Command 的所有已注册任务

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-tasks \ --window-id "mw-0c50858d01EXAMPLE" \ --filters "Key=Priority,Values=1" "Key=TaskType,Values=RUN_COMMAND"
Windows
aws ssm describe-maintenance-window-tasks ^ --window-id "mw-0c50858d01EXAMPLE" ^ --filters "Key=Priority,Values=1" "Key=TaskType,Values=RUN_COMMAND"

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

{
    "Tasks": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE",
            "TaskArn": "AWS-RunShellScript",
            "Type": "RUN_COMMAND",
            "Targets": [
                {
                    "Key": "InstanceIds",
                    "Values": [
                        "i-02573cafcfEXAMPLE"
                    ]
                }
            ],
            "TaskParameters": {},
            "Priority": 1,
            "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
            "MaxConcurrency": "1",
            "MaxErrors": "1"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowTaskId": "8a5c4629-31b0-4edd-8aea-33698EXAMPLE",
            "TaskArn": "AWS-UpdateSSMAgent",
            "Type": "RUN_COMMAND",
            "Targets": [
                {
                    "Key": "InstanceIds",
                    "Values": [
                        "i-0471e04240EXAMPLE"
                    ]
                }
            ],
            "TaskParameters": {},
            "Priority": 1,
            "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole",
            "MaxConcurrency": "1",
            "MaxErrors": "1",
            "Name": "My-Run-Command-Task",
            "Description": "My Run Command task to update SSM Agent on an instance"
        }
    ]
}

'describe-maintenance-windows-for-target' 的示例

列出与特定节点关联的维护时段目标或任务的相关信息

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-windows-for-target \ --resource-type INSTANCE \ --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" \ --max-results 10
Windows
aws ssm describe-maintenance-windows-for-target ^ --resource-type INSTANCE ^ --targets "Key=InstanceIds,Values=i-02573cafcfEXAMPLE" ^ --max-results 10

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

{
    "WindowIdentities": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "My-Second-Maintenance-Window"
        }
    ]
}

'describe-maintenance-window-executions' 的示例

列出在特定日期前运行的所有任务

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-executions \ --window-id "mw-9a8b7c6d5eEXAMPLE" \ --filters "Key=ExecutedBefore,Values=2019-05-12T05:00:00Z"
Windows
aws ssm describe-maintenance-window-executions ^ --window-id "mw-9a8b7c6d5eEXAMPLE" ^ --filters "Key=ExecutedBefore,Values=2019-05-12T05:00:00Z"

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

{
    "WindowExecutions": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
            "Status": "FAILED",
            "StatusDetails": "The following SSM parameters are invalid: LevelUp",
            "StartTime": 1557617747.993,
            "EndTime": 1557617748.101
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "WindowExecutionId": "791b72e0-f0da-4021-8b35-f95dfEXAMPLE",
            "Status": "SUCCESS",
            "StartTime": 1557594085.428,
            "EndTime": 1557594090.978
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowExecutionId": "ecec60fa-6bb0-4d26-98c7-140308EXAMPLE",
            "Status": "SUCCESS",
            "StartTime": 1557593793.483,
            "EndTime": 1557593798.978
        }
    ]
}
列出在特定日期后运行的所有任务

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-executions \ --window-id "mw-9a8b7c6d5eEXAMPLE" \ --filters "Key=ExecutedAfter,Values=2018-12-31T17:00:00Z"
Windows
aws ssm describe-maintenance-window-executions ^ --window-id "mw-9a8b7c6d5eEXAMPLE" ^ --filters "Key=ExecutedAfter,Values=2018-12-31T17:00:00Z"

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

{
    "WindowExecutions": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowExecutionId": "14bea65d-5ccc-462d-a2f3-e99c8EXAMPLE",
            "Status": "FAILED",
            "StatusDetails": "The following SSM parameters are invalid: LevelUp",
            "StartTime": 1557617747.993,
            "EndTime": 1557617748.101
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "WindowExecutionId": "791b72e0-f0da-4021-8b35-f95dfEXAMPLE",
            "Status": "SUCCESS",
            "StartTime": 1557594085.428,
            "EndTime": 1557594090.978
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "WindowExecutionId": "ecec60fa-6bb0-4d26-98c7-140308EXAMPLE",
            "Status": "SUCCESS",
            "StartTime": 1557593793.483,
            "EndTime": 1557593798.978
        }
    ]
}

'describe-maintenance-window-schedule' 的示例

显示特定节点接下来的十次已计划的维护时段运行

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-schedule \ --resource-type INSTANCE \ --targets "Key=InstanceIds,Values=i-07782c72faEXAMPLE" \ --max-results 10
Windows
aws ssm describe-maintenance-window-schedule ^ --resource-type INSTANCE ^ --targets "Key=InstanceIds,Values=i-07782c72faEXAMPLE" ^ --max-results 10

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

{
    "ScheduledWindowExecutions": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-05-18T23:35:24.902Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-05-25T23:35:24.902Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-06-01T23:35:24.902Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-06-08T23:35:24.902Z"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "My-Second-Maintenance-Window",
            "ExecutionTime": "2019-06-15T23:35:24.902Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-06-22T23:35:24.902Z"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "My-Second-Maintenance-Window",
            "ExecutionTime": "2019-06-29T23:35:24.902Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-07-06T23:35:24.902Z"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "My-Second-Maintenance-Window",
            "ExecutionTime": "2019-07-13T23:35:24.902Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "My-First-Maintenance-Window",
            "ExecutionTime": "2019-07-20T23:35:24.902Z"
        }
    ],
    "NextToken": "AAEABUXdceT92FvtKld/dGHELj5Mi+GKW/EXAMPLE"
}
显示使用特定键值对标记的节点的维护时段计划

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-schedule \ --resource-type INSTANCE \ --targets "Key=tag:prod,Values=rhel7"
Windows
aws ssm describe-maintenance-window-schedule ^ --resource-type INSTANCE ^ --targets "Key=tag:prod,Values=rhel7"

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

{
    "ScheduledWindowExecutions": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2019-10-20T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2019-10-21T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2019-10-22T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2019-10-23T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2019-10-24T05:34:56-07:00"
        }
    ],
    "NextToken": "AAEABccwSXqQRGKiTZ1yzGELR6cxW4W/EXAMPLE"
}
显示某个维护时段接下来的四个运行的开始时间

运行以下命令。

Linux & macOS
aws ssm describe-maintenance-window-schedule \ --window-id "mw-0c50858d01EXAMPLE" \ --max-results "4"
Windows
aws ssm describe-maintenance-window-schedule ^ --window-id "mw-0c50858d01EXAMPLE" ^ --max-results "4"

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

{
    "WindowSchedule": [
        {
            "ScheduledWindowExecutions": [
                {
                    "ExecutionTime": "2019-10-04T10:10:10Z",
                    "Name": "My-First-Maintenance-Window",
                    "WindowId": "mw-0c50858d01EXAMPLE"
                },
                {
                    "ExecutionTime": "2019-10-11T10:10:10Z",
                    "Name": "My-First-Maintenance-Window",
                    "WindowId": "mw-0c50858d01EXAMPLE"
                },
                {
                    "ExecutionTime": "2019-10-18T10:10:10Z",
                    "Name": "My-First-Maintenance-Window",
                    "WindowId": "mw-0c50858d01EXAMPLE"
                },
                {
                    "ExecutionTime": "2019-10-25T10:10:10Z",
                    "Name": "My-First-Maintenance-Window",
                    "WindowId": "mw-0c50858d01EXAMPLE"
                }
            ]
        }
    ]
}