AWS Systems Manager
用户指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

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

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

As you follow the steps in this tutorial, replace the values in italicized red text with your own options and IDs. For example, replace the maintenance window ID mw-0c50858d01EXAMPLE and the instance ID i-02573cafcfEXAMPLE with IDs of resources you create.

有关设置和配置 CLI 的信息,请参阅安装 AWS Command Line Interface配置 AWS Command Line Interface

'describe-maintenance-windows' 的示例

列出您的 AWS 账户中所有的维护时段

运行以下命令:

aws ssm describe-maintenance-windows

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

{
   "WindowIdentities":[
      {
         "Duration":2,
         "Cutoff":0,
         "WindowId":"mw-0c50858d01EXAMPLE",
         "Enabled":true,
         "Name":"IAD-Every-15-Minutes"
      },
      {
         "Duration":4,
         "Cutoff":1,
         "WindowId":"mw-9a8b7c6d5eEXAMPLE",
         "Enabled":true,
         "Name":"My-First-Maintenance-Window"
      },
      {
         "Duration":8,
         "Cutoff":2,
         "WindowId":"mw-369258147YEXAMPLE",
         "Enabled":false,
         "Name":"Every-Day"
      }
   ]
}

列出所有已启用的维护时段

运行以下命令:

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

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

{
   "WindowIdentities":[
      {
         "Duration":2,
         "Cutoff":0,
         "WindowId":"mw-0c50858d01EXAMPLE",
         "Enabled":true,
         "Name":"IAD-Every-15-Minutes"
      },
      {
         "Duration":4,
         "Cutoff":1,
         "WindowId":"mw-9a8b7c6d5eEXAMPLE",
         "Enabled":true,
         "Name":"My-First-Maintenance-Window"
      }
   ]
}

列出所有已禁用的维护时段

运行以下命令:

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

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

{
   "WindowIdentities":[
      {
         "Duration":8,
         "Cutoff":2,
         "WindowId":"mw-369258147YEXAMPLE",
         "Enabled":false,
         "Name":"Every-Day"
      }
   ]
}

列出名称以特定前缀开头的所有维护时段

运行以下命令:

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

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

{
   "WindowIdentities":[
      {
         "Duration":4,
         "Cutoff":1,
         "WindowId":"mw-369258147YEXAMPLE",
         "Enabled":true,
         "Name":"My-First-Maintenance-Window"
      }
   ]
}

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

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

运行以下命令:

aws ssm describe-maintenance-window-targets --window-id "mw-ab12cd34eEXAMPLE" --filters "Key=OwnerInformation,Values=Single instance"

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

{
   "Targets":[
      {
         "TargetType":"INSTANCE",
         "TagFilters":[

         ],
         "TargetIds":[
            "i-02573cafcfEXAMPLE"
         ],
         "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-EXAMPLE1-1a2",
         "OwnerInformation":"Single instance"
      }
   ]
}

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

显示将调用 AWS-RunPowerShellScript Run Command 的所有已注册任务

运行以下命令:

aws ssm describe-maintenance-window-tasks --window-id "mw-9a8b7c6d5eEXAMPLE" --filters "Key=TaskArn,Values=AWS-RunPowerShellScript"

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

{
   "Tasks":[
      {
         "ServiceRoleArn":"arn:aws:iam::111122223333:role/MW-Role",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3EXAMPLE",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "driverquery.exe"
               ]
            }
         },
         "Priority":3,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"i-02573cafcfEXAMPLE",
               "TaskTargetType":"INSTANCE"
            }
         ]
      },
      {
         "ServiceRoleArn":"arn:aws:iam::111122223333:role/MW-Role",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"33333-33333-333-33333",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "ipconfig.exe"
               ]
            }
         },
         "Priority":1,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"44444-444-4444-444444",
               "TaskTargetType":"WINDOW_TARGET"
            }
         ]
      }
   ]
}

显示优先级为“3”的所有已注册任务

运行以下命令:

aws ssm describe-maintenance-window-tasks --window-id "mw-9a8b7c6d5eEXAMPLE" --filters "Key=Priority,Values=3"

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

{
   "Tasks":[
      {
         "ServiceRoleArn":"arn:aws:iam::111122223333:role/MW-Role",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"333333-333-33333-33333",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "driverquery.exe"
               ]
            }
         },
         "Priority":3,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"i-02573cafcfEXAMPLE",
               "TaskTargetType":"INSTANCE"
            }
         ]
      }
   ]
}

显示优先级为 1 且使用 Run Command 的所有已注册任务

运行以下命令:

aws ssm describe-maintenance-window-tasks --window-id "mw-ab12cd34ef56gh78" --filters "Key=Priority,Values=1" "Key=TaskType,Values=RUN_COMMAND"

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

{
   "Tasks":[
      {
         "ServiceRoleArn":"arn:aws:iam::111122223333:role/MW-Role",
         "MaxErrors":"1",
         "TaskArn":"AWS-RunPowerShellScript",
         "MaxConcurrency":"1",
         "WindowTaskId":"66666-555-66-555-6666",
         "TaskParameters":{
            "commands":{
               "Values":[
                  "ipconfig.exe"
               ]
            }
         },
         "Priority":1,
         "Type":"RUN_COMMAND",
         "Targets":[
            {
               "TaskTargetId":"777-77-777-7777777",
               "TaskTargetType":"WINDOW_TARGET"
            }
         ]
      }
   ]
}

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

列出与使用特定键标记的实例关联的维护时段目标或任务的相关信息

运行以下命令:

aws ssm describe-maintenance-windows-for-target --resource-type INSTANCE --targets "Key=tag-key,Values=prod"

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

{
    "WindowIdentities": [
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "DemoRateStartDate"
        }
    ]
}

列出与使用特定键值对标记的实例关联的维护时段目标或任务的相关信息

运行以下命令:

aws ssm describe-maintenance-windows-for-target --resource-type INSTANCE --targets "Key=tag:prod,Values=rhel7"

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

{
    "WindowIdentities": [
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "DemoCronEndDate"
        }
    ]
}

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

运行以下命令:

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

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

{
    "WindowIdentities": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "DemoCronEndDate"
        }
    ]
}

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

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

运行以下命令:

aws ssm describe-maintenance-window-executions --window-id "111122223333" --filters "Key=ExecutedBefore,Values=2016-11-04T05:00:00Z"

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

{
   "WindowExecutions":[
      {
         "Status":"SUCCESS",
         "EndTime":1478229594.666,
         "WindowExecutionId":"",
         "StartTime":1478229594.666
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"06dc5f8a-9ef0-4ae9-a466-ada2dEXAMPLE",
         "StartTime":1478230495.469
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"57ad6419-023e-44b0-a831-66873EXAMPLE",
         "StartTime":1478231395.677
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"ed1372b7-866b-4d64-bc2a-bbfd5EXAMPLE",
         "StartTime":1478232295.529
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"154eb2fa-6390-4cb7-8c9e-55686EXAMPLE",
         "StartTime":1478233195.687
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"1c4de752-eff6-4778-b477-1681cEXAMPLE",
         "StartTime":1478234095.553
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"56062f75-e4d8-483f-b5c2-906d6EXAMPLE",
         "StartTime":1478234995.12
      }
   ]
}

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

运行以下命令:

aws ssm describe-maintenance-window-executions --window-id "mw-9a8b7c6d5eEXAMPLE" --filters "Key=ExecutedAfter,Values=2016-11-04T17:00:00Z"

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

{
   "WindowExecutions":[
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"33333-4444-444-5555555",
         "StartTime":1478279095.042
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"55555-6666-6666-777777",
         "StartTime":1478279994.958
      },
      {
         "Status":"SUCCESS",
         "WindowExecutionId":"8888-888-888-888888",
         "StartTime":1478280895.149
      }
   ]
}

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

显示特定实例接下来的十个已计划的维护时段运行

运行以下命令:

aws ssm describe-maintenance-window-schedule --resource-type INSTANCE --targets "Key=InstanceIds,Values=i-07782c72faEXAMPLE" --max-results 10

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

{
    "ScheduledWindowExecutions": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-20T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-21T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-22T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-23T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0bc0739f959f09230",
            "Name": "DemoCronEndDate",
            "ExecutionTime": "2018-10-23T16:00Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-24T05:34:56-07:00"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "DemoCronEndDate",
            "ExecutionTime": "2018-10-24T16:00Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-25T05:34:56-07:00"
        },
        {
            "WindowId": "mw-9a8b7c6d5eEXAMPLE",
            "Name": "DemoCronEndDate",
            "ExecutionTime": "2018-10-25T16:00Z"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-26T05:34:56-07:00"
        }
    ],
    "NextToken": "AAEABUXdceT92FvtKld/dGHELj5Mi+GKW/EXAMPLE"
}

显示使用特定键值对标记的实例的维护时段计划

运行以下命令:

aws ssm describe-maintenance-window-schedule --resource-type INSTANCE --targets "Key=tag:prod,Values=rhel7"

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

{
    "ScheduledWindowExecutions": [
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-20T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-21T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-22T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-23T05:34:56-07:00"
        },
        {
            "WindowId": "mw-0c50858d01EXAMPLE",
            "Name": "DemoRateStartDate",
            "ExecutionTime": "2018-10-24T05:34:56-07:00"
        }
    ],
    "NextToken": "AAEABccwSXqQRGKiTZ1yzGELR6cxW4W/EXAMPLE"
}

显示某个维护时段接下来的四个运行的开始时间

运行以下命令:

aws ssm describe-maintenance-window-schedule --window-id "mw-ab12cd34eEXAMPLE" --max-results "4"

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

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