本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeMaintenanceWindowTasks
搭配 AWS SDK或 使用 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 的維護時段的所有任務,並使用執行命令
此
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" } ] }
如需詳細資訊,請參閱 Systems Manager 使用者指南中的檢視維護時段 (AWS CLI) 的相關資訊。 AWS
-
如需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中的 。
-
如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 搭配 使用 Systems Manager AWS SDK。本主題也包含入門的相關資訊,以及先前SDK版本的詳細資訊。