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

演练:列出有关 Maintenance Window 的信息

本部分包含的命令可帮助您更新Maintenance Window、任务、执行和调用或获取相关信息。

列出您的 AWS 账户中所有的Maintenance Window

按如下所示运行命令。

aws ssm describe-maintenance-windows

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

{ "WindowIdentities":[ { "Duration":2, "Cutoff":0, "WindowId":"mw-ab12cd34ef56gh78", "Enabled":true, "Name":"IAD-Every-15-Minutes" }, { "Duration":4, "Cutoff":1, "WindowId":"mw-1a2b3c4d5e6f7g8h9", "Enabled":true, "Name":"My-First-Maintenance-Window" }, { "Duration":8, "Cutoff":2, "WindowId":"mw-123abc456def789", "Enabled":false, "Name":"Every-Day" } ] }

列出所有已启用的Maintenance Window

按如下所示运行命令。

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

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

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

列出所有已禁用的Maintenance Window

按如下所示运行命令。

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

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

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

按名称筛选

在本示例中,命令将返回所有名称以“My”开头的Maintenance Window。

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

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

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

显示匹配特定所有者信息值的Maintenance Window的目标

按如下所示运行命令。

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

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

{ "Targets":[ { "TargetType":"INSTANCE", "TagFilters":[ ], "TargetIds":[ "i-1a2b3c4d5e6f7g8h9" ], "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d-1a2", "OwnerInformation":"Single instance" } ] }

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

按如下所示运行命令。

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

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

{ "Tasks":[ { "ServiceRoleArn":"arn:aws:iam::444444444444:role/MW-Role", "MaxErrors":"1", "TaskArn":"AWS-RunPowerShellScript", "MaxConcurrency":"1", "WindowTaskId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6c", "TaskParameters":{ "commands":{ "Values":[ "driverquery.exe" ] } }, "Priority":3, "Type":"RUN_COMMAND", "Targets":[ { "TaskTargetId":"i-1a2b3c4d5e6f7g8h9", "TaskTargetType":"INSTANCE" } ] }, { "ServiceRoleArn":"arn:aws:iam::333333333333: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-ab12cd34ef56gh78" --filters "Key=Priority,Values=3"

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

{ "Tasks":[ { "ServiceRoleArn":"arn:aws:iam::222222222: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-1a2b3c4d5e6f7g8h9", "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::333333333: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" } ] } ] }

列出在某个日期之前运行的所有任务

按如下所示运行命令。

aws ssm describe-maintenance-window-executions --window-id "mw-ab12cd34ef56gh78" --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-ada2d4ce2d22", "StartTime":1478230495.469 }, { "Status":"SUCCESS", "WindowExecutionId":"57ad6419-023e-44b0-a831-6687334390b2", "StartTime":1478231395.677 }, { "Status":"SUCCESS", "WindowExecutionId":"ed1372b7-866b-4d64-bc2a-bbfd5195f4ae", "StartTime":1478232295.529 }, { "Status":"SUCCESS", "WindowExecutionId":"154eb2fa-6390-4cb7-8c9e-55686b88c7b3", "StartTime":1478233195.687 }, { "Status":"SUCCESS", "WindowExecutionId":"1c4de752-eff6-4778-b477-1681c6c03cf1", "StartTime":1478234095.553 }, { "Status":"SUCCESS", "WindowExecutionId":"56062f75-e4d8-483f-b5c2-906d613409a4", "StartTime":1478234995.12 } ] }

列出在某个日期之后运行的所有任务

按如下所示运行命令。

aws ssm describe-maintenance-window-executions --window-id "mw-ab12cd34ef56gh78" --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 } ] }