文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeMaintenanceWindowTasks
搭配 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" } ] }
如需詳細資訊,請參閱 AWS Systems Manager 使用者指南中的檢視維護時段 (AWS CLI) 的相關資訊。
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeMaintenanceWindowTasks
。
-
- PowerShell
-
- for 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。
-