AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DescribeMaintenanceWindowTasks
与 a 一起使用 CLI
以下代码示例演示如何使用 DescribeMaintenanceWindowTasks
。
- CLI
-
- AWS CLI
-
示例 1:列出维护时段内的所有任务
以下
describe-maintenance-window-tasks
示例列出指定维护时段内的所有任务。aws ssm describe-maintenance-window-tasks \ --window-id
"mw-06cf17cbefEXAMPLE"
输出:
{ "Tasks": [ { "WindowId": "mw-06cf17cbefEXAMPLE", "WindowTaskId": "018b31c3-2d77-4b9e-bd48-c91edEXAMPLE", "TaskArn": "AWS-RestartEC2Instance", "TaskParameters": {}, "Type": "AUTOMATION", "Description": "Restarting EC2 Instance for maintenance", "MaxConcurrency": "1", "MaxErrors": "1", "Name": "My-Automation-Example-Task", "Priority": 0, "ServiceRoleArn": "arn:aws:iam::111222333444:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "da89dcc3-7f9c-481d-ba2b-edcb7EXAMPLE" ] } ] }, { "WindowId": "mw-06cf17cbefEXAMPLE", "WindowTaskId": "1943dee0-0a17-4978-9bf4-3cc2fEXAMPLE", "TaskArn": "AWS-DisableS3BucketPublicReadWrite", "TaskParameters": {}, "Type": "AUTOMATION", "Description": "Automation task to disable read/write access on public S3 buckets", "MaxConcurrency": "10", "MaxErrors": "5", "Name": "My-Disable-S3-Public-Read-Write-Access-Automation-Task", "Priority": 0, "ServiceRoleArn": "arn:aws:iam::111222333444:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "da89dcc3-7f9c-481d-ba2b-edcb7EXAMPLE" ] } ] } ] }
示例 2:列出调用 AWS-RunPowerShellScript 命令文档的维护时段的所有任务
以下
describe-maintenance-window-tasks
示例列出在调用AWS-RunPowerShellScript
命令文档的指定维护时段内的所有任务。aws ssm describe-maintenance-window-tasks \ --window-id
"mw-ab12cd34eEXAMPLE"
\ --filters"Key=TaskArn,Values=AWS-RunPowerShellScript"
输出:
{ "Tasks": [ { "WindowId": "mw-ab12cd34eEXAMPLE", "WindowTaskId": "0d36e6b4-3a4f-411e-adcb-3558eEXAMPLE", "TaskArn": "AWS-RunPowerShellScript", "Type": "RUN_COMMAND", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "da89dcc3-7f9c-481d-ba2b-edcb7EXAMPLE" ] } ], "TaskParameters": {}, "Priority": 1, "ServiceRoleArn": "arn:aws:iam::111222333444:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM", "MaxConcurrency": "1", "MaxErrors": "1", "Name": "MyTask" } ] }
示例 3:列出优先级为 3 的维护时段内的所有任务
以下
describe-maintenance-window-tasks
示例列出指定维护时段内Priority
为3
的所有任务。aws ssm describe-maintenance-window-tasks \ --window-id
"mw-ab12cd34eEXAMPLE"
\ --filters"Key=Priority,Values=3"
输出:
{ "Tasks": [ { "WindowId": "mw-ab12cd34eEXAMPLE", "WindowTaskId": "0d36e6b4-3a4f-411e-adcb-3558eEXAMPLE", "TaskArn": "AWS-RunPowerShellScript", "Type": "RUN_COMMAND", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "da89dcc3-7f9c-481d-ba2b-edcb7EXAMPLE" ] } ], "TaskParameters": {}, "Priority": 3, "ServiceRoleArn": "arn:aws:iam::111222333444:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM", "MaxConcurrency": "1", "MaxErrors": "1", "Name": "MyRunCommandTask" }, { "WindowId": "mw-ab12cd34eEXAMPLE", "WindowTaskId": "ee45feff-ad65-4a6c-b478-5cab8EXAMPLE", "TaskArn": "AWS-RestartEC2Instance", "Type": "AUTOMATION", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "da89dcc3-7f9c-481d-ba2b-edcb7EXAMPLE" ] } ], "TaskParameters": {}, "Priority": 3, "ServiceRoleArn": "arn:aws:iam::111222333444:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM", "MaxConcurrency": "10", "MaxErrors": "5", "Name": "My-Automation-Task", "Description": "A description for my Automation task" } ] }
示例 4:列出优先级为 1 并使用 Run Command 的维护时段内的所有任务
此
describe-maintenance-window-tasks
示例列出指定维护时段内Priority
为1
并使用Run Command
的所有任务。aws ssm describe-maintenance-window-tasks \ --window-id
"mw-ab12cd34eEXAMPLE"
\ --filters"Key=Priority,Values=1"
"Key=TaskType,Values=RUN_COMMAND"
输出:
{ "Tasks": [ { "WindowId": "mw-ab12cd34eEXAMPLE", "WindowTaskId": "0d36e6b4-3a4f-411e-adcb-3558eEXAMPLE", "TaskArn": "AWS-RunPowerShellScript", "Type": "RUN_COMMAND", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "da89dcc3-7f9c-481d-ba2b-edcb7EXAMPLE" ] } ], "TaskParameters": {}, "Priority": 1, "ServiceRoleArn": "arn:aws:iam::111222333444:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM", "MaxConcurrency": "1", "MaxErrors": "1", "Name": "MyRunCommandTask" } ] }
有关更多信息,请参阅《S AWS ystems Manager 用户指南》中的 “查看有关维护窗口的信息 (AWS CLI)”。
-
有关API详细信息,请参阅 “DescribeMaintenanceWindowTasks AWS CLI
命令参考”。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此示例列出维护时段的所有任务。
Get-SSMMaintenanceWindowTaskList -WindowId "mw-06cf17cbefcb4bf4f"
输出:
LoggingInfo : MaxConcurrency : 1 MaxErrors : 1 Priority : 10 ServiceRoleArn : arn:aws:iam::123456789012:role/MaintenanceWindowsRole Targets : {InstanceIds} TaskArn : AWS-RunShellScript TaskParameters : {[commands, Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression]} Type : RUN_COMMAND WindowId : mw-06cf17cbefcb4bf4f WindowTaskId : a23e338d-ff30-4398-8aa3-09cd052ebf17
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DescribeMaintenanceWindowTasks中的。
-