AWS Systems Manager Change Manager is no longer open to new customers. Existing customers can continue to use the service as normal. For more information, see AWS Systems Manager Change Manager availability change.
Use RegisterTaskWithMaintenanceWindow with a CLI
The following code examples show how to use RegisterTaskWithMaintenanceWindow.
- CLI
-
- AWS CLI
-
Example 1: To register an Automation task with a maintenance window
The following
register-task-with-maintenance-windowexample registers an Automation task with a maintenance window that is targeted at an instance.aws ssm register-task-with-maintenance-window \ --window-id"mw-082dcd7649EXAMPLE"\ --targetsKey=InstanceIds,Values=i-1234520122EXAMPLE\ --task-arnAWS-RestartEC2Instance\ --service-role-arnarn:aws:iam::111222333444:role/SSM--task-typeAUTOMATION\ --task-invocation-parameters "{\"Automation\":{\"DocumentVersion\":\"\$LATEST\",\"Parameters\":{\"InstanceId\":[\"{{RESOURCE_ID}}\"]}}}" \ --priority0\ --max-concurrency1\ --max-errors1\ --name"AutomationExample"\ --description"Restarting EC2 Instance for maintenance"Output:
{ "WindowTaskId":"11144444-5555-6666-7777-88888888" }For more information, see Register a Task with the Maintenance Window (AWS CLI) in the AWS Systems Manager User Guide.
Example 2: To register a Lambda task with a Maintenance Window
The following
register-task-with-maintenance-windowexample registers a Lambda task with a Maintenance Window that is targeted at an instance.aws ssm register-task-with-maintenance-window \ --window-id"mw-082dcd7649dee04e4"\ --targetsKey=InstanceIds,Values=i-12344d305eEXAMPLE\ --task-arnarn:aws:lambda:us-east-1:111222333444:function:SSMTestLAMBDA\ --service-role-arnarn:aws:iam::111222333444:role/SSM\ --task-typeLAMBDA\ --task-invocation-parameters '{"Lambda":{"Payload":"{\"InstanceId\":\"{{RESOURCE_ID}}\",\"targetType\":\"{{TARGET_TYPE}}\"}","Qualifier":"$LATEST"}}' \ --priority0\ --max-concurrency10\ --max-errors5\ --name"Lambda_Example"\ --description"My Lambda Example"Output:
{ "WindowTaskId":"22244444-5555-6666-7777-88888888" }For more information, see Register a Task with the Maintenance Window (AWS CLI) in the AWS Systems Manager User Guide.
Example 3: To register a Run Command task with a maintenance window
The following
register-task-with-maintenance-windowexample registers a Run Command task with a maintenance window that is targeted at an instance.aws ssm register-task-with-maintenance-window \ --window-id"mw-082dcd7649dee04e4"\ --targets"Key=InstanceIds,Values=i-12344d305eEXAMPLE"\ --service-role-arn"arn:aws:iam::111222333444:role/SSM"\ --task-type"RUN_COMMAND"\ --name"SSMInstallPowerShellModule"\ --task-arn"AWS-InstallPowerShellModule"\ --task-invocation-parameters "{\"RunCommand\":{\"Comment\":\"\",\"OutputS3BucketName\":\"runcommandlogs\",\"Parameters\":{\"commands\":[\"Get-Module -ListAvailable\"],\"executionTimeout\":[\"3600\"],\"source\":[\"https:\/\/gallery.technet.microsoft.com\/EZOut-33ae0fb7\/file\/110351\/1\/EZOut.zip\"],\"workingDirectory\":[\"\\\\\"]},\"TimeoutSeconds\":600}}" \ --max-concurrency 1 \ --max-errors 1 \ --priority10Output:
{ "WindowTaskId":"33344444-5555-6666-7777-88888888" }For more information, see Register a Task with the Maintenance Window (AWS CLI) in the AWS Systems Manager User Guide.
Example 4: To register a Step Functions task with a maintenance window
The following
register-task-with-maintenance-windowexample registers a Step Functions task with a maintenance window that is targeted at an instance.aws ssm register-task-with-maintenance-window \ --window-id"mw-1234d787d6EXAMPLE"\ --targetsKey=WindowTargetIds,Values=12347414-69c3-49f8-95b8-ed2dcEXAMPLE\ --task-arnarn:aws:states:us-east-1:111222333444:stateMachine:SSMTestStateMachine\ --service-role-arnarn:aws:iam::111222333444:role/MaintenanceWindows\ --task-typeSTEP_FUNCTIONS\ --task-invocation-parameters '{"StepFunctions":{"Input":"{\"InstanceId\":\"{{RESOURCE_ID}}\"}"}}' \ --priority0\ --max-concurrency10\ --max-errors5\ --name"Step_Functions_Example"\ --description"My Step Functions Example"Output:
{ "WindowTaskId":"44444444-5555-6666-7777-88888888" }For more information, see Register a Task with the Maintenance Window (AWS CLI) in the AWS Systems Manager User Guide.
Example 5: To register a task using a maintenance windows target ID
The following
register-task-with-maintenance-windowexample registers a task using a maintenance window target ID. The maintenance window target ID was in the output of theaws ssm register-target-with-maintenance-windowcommand. You can also retrieve it from the output of theaws ssm describe-maintenance-window-targetscommand.aws ssm register-task-with-maintenance-window \ --targets"Key=WindowTargetIds,Values=350d44e6-28cc-44e2-951f-4b2c9EXAMPLE"\ --task-arn"AWS-RunShellScript"\ --service-role-arn"arn:aws:iam::111222333444:role/MaintenanceWindowsRole"\ --window-id"mw-ab12cd34eEXAMPLE"\ --task-type"RUN_COMMAND"\ --task-parameters "{\"commands\":{\"Values\":[\"df\"]}}" \ --max-concurrency1\ --max-errors1\ --priority10Output:
{ "WindowTaskId":"33344444-5555-6666-7777-88888888" }For more information, see Register a Task with the Maintenance Window (AWS CLI) in the AWS Systems Manager User Guide.
-
For API details, see RegisterTaskWithMaintenanceWindow
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example registers a task with a maintenance window using an instance ID. The output is the Task ID.
$parameters = @{} $parameterValues = New-Object Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression $parameterValues.Values = @("Install") $parameters.Add("Operation", $parameterValues) Register-SSMTaskWithMaintenanceWindow -WindowId "mw-03a342e62c96d31b0" -ServiceRoleArn "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" -MaxConcurrency 1 -MaxError 1 -TaskArn "AWS-RunShellScript" -Target @{ Key="InstanceIds";Values="i-0000293ffd8c57862" } -TaskType "RUN_COMMAND" -Priority 10 -TaskParameter $parametersOutput:
f34a2c47-ddfd-4c85-a88d-72366b69af1bExample 2: This example registers a task with a maintenance window using a target ID. The output is the Task ID.
$parameters = @{} $parameterValues = New-Object Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression $parameterValues.Values = @("Install") $parameters.Add("Operation", $parameterValues) register-ssmtaskwithmaintenancewindow -WindowId "mw-03a342e62c96d31b0" -ServiceRoleArn "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" -MaxConcurrency 1 -MaxError 1 -TaskArn "AWS-RunShellScript" -Target @{ Key="WindowTargetIds";Values="350d44e6-28cc-44e2-951f-4b2c985838f6" } -TaskType "RUN_COMMAND" -Priority 10 -TaskParameter $parametersOutput:
f34a2c47-ddfd-4c85-a88d-72366b69af1bExample 3: This example creates a parameter object for the run command document
AWS-RunPowerShellScriptand creates a task with given maintenance window using target ID. The return output is the task ID.$parameters = [Collections.Generic.Dictionary[String,Collections.Generic.List[String]]]::new() $parameters.Add("commands",@("ipconfig","dir env:\computername")) $parameters.Add("executionTimeout",@(3600)) $props = @{ WindowId = "mw-0123e4cce56ff78ae" ServiceRoleArn = "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" MaxConcurrency = 1 MaxError = 1 TaskType = "RUN_COMMAND" TaskArn = "AWS-RunPowerShellScript" Target = @{Key="WindowTargetIds";Values="fe1234ea-56d7-890b-12f3-456b789bee0f"} Priority = 1 RunCommand_Parameter = $parameters Name = "set-via-cmdlet" } Register-SSMTaskWithMaintenanceWindow @propsOutput:
f1e2ef34-5678-12e3-456a-12334c5c6cbeExample 4: This example registers an AWS Systems Manager Automation task by using a document named
Create-Snapshots.$automationParameters = @{} $automationParameters.Add( "instanceId", @("{{ TARGET_ID }}") ) $automationParameters.Add( "AutomationAssumeRole", @("{arn:aws:iam::111111111111:role/AutomationRole}") ) $automationParameters.Add( "SnapshotTimeout", @("PT20M") ) Register-SSMTaskWithMaintenanceWindow -WindowId mw-123EXAMPLE456` -ServiceRoleArn "arn:aws:iam::123456789012:role/MW-Role"` -MaxConcurrency 1 -MaxError 1 -TaskArn "CreateVolumeSnapshots"` -Target @{ Key="WindowTargetIds";Values="4b5acdf4-946c-4355-bd68-4329a43a5fd1" }` -TaskType "AUTOMATION"` -Priority 4` -Automation_DocumentVersion '$DEFAULT' -Automation_Parameter $automationParameters -Name "Create-Snapshots"-
For API details, see RegisterTaskWithMaintenanceWindow in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example registers a task with a maintenance window using an instance ID. The output is the Task ID.
$parameters = @{} $parameterValues = New-Object Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression $parameterValues.Values = @("Install") $parameters.Add("Operation", $parameterValues) Register-SSMTaskWithMaintenanceWindow -WindowId "mw-03a342e62c96d31b0" -ServiceRoleArn "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" -MaxConcurrency 1 -MaxError 1 -TaskArn "AWS-RunShellScript" -Target @{ Key="InstanceIds";Values="i-0000293ffd8c57862" } -TaskType "RUN_COMMAND" -Priority 10 -TaskParameter $parametersOutput:
f34a2c47-ddfd-4c85-a88d-72366b69af1bExample 2: This example registers a task with a maintenance window using a target ID. The output is the Task ID.
$parameters = @{} $parameterValues = New-Object Amazon.SimpleSystemsManagement.Model.MaintenanceWindowTaskParameterValueExpression $parameterValues.Values = @("Install") $parameters.Add("Operation", $parameterValues) register-ssmtaskwithmaintenancewindow -WindowId "mw-03a342e62c96d31b0" -ServiceRoleArn "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" -MaxConcurrency 1 -MaxError 1 -TaskArn "AWS-RunShellScript" -Target @{ Key="WindowTargetIds";Values="350d44e6-28cc-44e2-951f-4b2c985838f6" } -TaskType "RUN_COMMAND" -Priority 10 -TaskParameter $parametersOutput:
f34a2c47-ddfd-4c85-a88d-72366b69af1bExample 3: This example creates a parameter object for the run command document
AWS-RunPowerShellScriptand creates a task with given maintenance window using target ID. The return output is the task ID.$parameters = [Collections.Generic.Dictionary[String,Collections.Generic.List[String]]]::new() $parameters.Add("commands",@("ipconfig","dir env:\computername")) $parameters.Add("executionTimeout",@(3600)) $props = @{ WindowId = "mw-0123e4cce56ff78ae" ServiceRoleArn = "arn:aws:iam::123456789012:role/MaintenanceWindowsRole" MaxConcurrency = 1 MaxError = 1 TaskType = "RUN_COMMAND" TaskArn = "AWS-RunPowerShellScript" Target = @{Key="WindowTargetIds";Values="fe1234ea-56d7-890b-12f3-456b789bee0f"} Priority = 1 RunCommand_Parameter = $parameters Name = "set-via-cmdlet" } Register-SSMTaskWithMaintenanceWindow @propsOutput:
f1e2ef34-5678-12e3-456a-12334c5c6cbeExample 4: This example registers an AWS Systems Manager Automation task by using a document named
Create-Snapshots.$automationParameters = @{} $automationParameters.Add( "instanceId", @("{{ TARGET_ID }}") ) $automationParameters.Add( "AutomationAssumeRole", @("{arn:aws:iam::111111111111:role/AutomationRole}") ) $automationParameters.Add( "SnapshotTimeout", @("PT20M") ) Register-SSMTaskWithMaintenanceWindow -WindowId mw-123EXAMPLE456` -ServiceRoleArn "arn:aws:iam::123456789012:role/MW-Role"` -MaxConcurrency 1 -MaxError 1 -TaskArn "CreateVolumeSnapshots"` -Target @{ Key="WindowTargetIds";Values="4b5acdf4-946c-4355-bd68-4329a43a5fd1" }` -TaskType "AUTOMATION"` -Priority 4` -Automation_DocumentVersion '$DEFAULT' -Automation_Parameter $automationParameters -Name "Create-Snapshots"-
For API details, see RegisterTaskWithMaintenanceWindow in AWS Tools for PowerShell Cmdlet Reference (V5).
-
For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.