Tutorial: Update a maintenance window using the AWS CLI
This tutorial demonstrates how to use the AWS Command Line Interface (AWS CLI) to update a maintenance window. It also shows you how to update different task types, including those for AWS Systems Manager Run Command and Automation, AWS Lambda, and AWS Step Functions.
The examples in this section use the following Systems Manager actions for updating a maintenance window:
For information about using the Systems Manager console to update a maintenance window, see Update or delete maintenance window resources using the console.
As you follow the steps in this tutorial, replace the values in italicized
red
text with your own options and IDs. For example,
replace the maintenance window ID mw-0c50858d01EXAMPLE
and the instance ID
i-02573cafcfEXAMPLE
with IDs of resources you create.
To update a maintenance window using the AWS CLI
-
Open the AWS CLI and run the following command to update a target to include a name and a description.
The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE", "Targets": [ { "Key": "InstanceIds", "Values": [ "i-02573cafcfEXAMPLE" ] } ], "Name": "My-Maintenance-Window-Target", "Description": "Description for my maintenance window target" }
-
Run the following command to use the
replace
option to remove the description field and add an additional target. The description field is removed, because the update doesn't include the field (a null value). Be sure to specify an additional node that has been configured for use with Systems Manager.The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE", "Targets": [ { "Key": "InstanceIds", "Values": [ "i-02573cafcfEXAMPLE", "i-0471e04240EXAMPLE" ] } ], "Name": "My-Maintenance-Window-Target" }
-
The
start-date
option allows you to delay activation of a maintenance window until a specified future date. Theend-date
option allows you to set a date and time in the future after which the maintenance window no longer runs. Specify the options in ISO-8601 Extended format.Run the following command to specify a date and time range for regularly scheduled maintenance window executions.
-
Run the following command to update a Run Command task.
Tip
If your target is an Amazon Elastic Compute Cloud (Amazon EC2) instance for Windows Server, change
df
toipconfig
, andAWS-RunShellScript
toAWS-RunPowerShellScript
in the following command.The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ] } ], "TaskArn": "AWS-RunShellScript", "ServiceRoleArn": "arn:aws:iam::111122223333:role/MaintenanceWindowsRole", "TaskParameters": {}, "TaskInvocationParameters": { "RunCommand": { "Comment": "Revising my Run Command task", "Parameters": { "commands": [ "df" ] } } }, "Priority": 1, "MaxConcurrency": "10", "MaxErrors": "4", "Name": "My-Task-Name", "Description": "A description for my Run Command task" }
-
Adapt and run the following command to update a Lambda task.
The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE", "Targets": [ { "Key": "WindowTargetIds", "Values": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" } ], "TaskArn": "arn:aws:lambda:us-east-2:111122223333:function:SSMTestLambda", "ServiceRoleArn": "arn:aws:iam::111122223333:role/MaintenanceWindowsRole", "TaskParameters": {}, "TaskInvocationParameters": { "Lambda": { "Payload": "e30=" } }, "Priority": 1, "MaxConcurrency": "10", "MaxErrors": "5", "Name": "New-Lambda-Task-Name", "Description": "A description for my Lambda task" }
-
If you're updating a Step Functions task, adapt and run the following command to update its task-invocation-parameters.
The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ] } ], "TaskArn": "arn:aws:states:us-east-2:111122223333:execution:SSMStepFunctionTest", "ServiceRoleArn": "arn:aws:iam::111122223333:role/MaintenanceWindowsRole", "TaskParameters": {}, "TaskInvocationParameters": { "StepFunctions": { "Input": "{\"instanceId\":\"{{RESOURCE_ID}}\"}" } }, "Priority": 0, "MaxConcurrency": "10", "MaxErrors": "5", "Name": "My-Step-Functions-Task", "Description": "A description for my Step Functions task" }
-
Run the following command to unregister a target from a maintenance window. This example uses the
safe
parameter to determine if the target is referenced by any tasks and therefore safe to unregister.The system returns information similar to the following.
An error occurred (TargetInUseException) when calling the DeregisterTargetFromMaintenanceWindow operation: This Target cannot be deregistered because it is still referenced in Task: 4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE
-
Run the following command to unregister a target from a maintenance window even if the target is referenced by a task. You can force the unregister operation by using the
no-safe
parameter.The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTargetId": "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" }
-
Run the following command to update a Run Command task. This example uses a Systems Manager Parameter Store parameter called
UpdateLevel
, which is formatted as follows: '{{ssm:UpdateLevel}}
'The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE", "Targets": [ { "Key": "InstanceIds", "Values": [ "i-02573cafcfEXAMPLE" ] } ], "TaskArn": "AWS-RunShellScript", "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole", "TaskParameters": {}, "TaskInvocationParameters": { "RunCommand": { "Comment": "A comment for my task update", "Parameters": { "UpdateLevel": [ "{{ssm:UpdateLevel}}" ] } } }, "Priority": 10, "MaxConcurrency": "1", "MaxErrors": "1" }
-
Run the following command to update an Automation task to specify
WINDOW_ID
andWINDOW_TASK_ID
parameters for thetask-invocation-parameters
parameter:The system returns information similar to the following.
{ "WindowId": "mw-0c50858d01EXAMPLE", "WindowTaskId": "4f7ca192-7e9a-40fe-9192-5cb15EXAMPLE", "Targets": [ { "Key": "WindowTargetIds", "Values": [ "e32eecb2-646c-4f4b-8ed1-205fbEXAMPLE" ] } ], "TaskArn": "AutoTestDoc", "ServiceRoleArn": "arn:aws:iam::111122223333:role/MyMaintenanceWindowServiceRole", "TaskParameters": {}, "TaskInvocationParameters": { "Automation": { "Parameters": { "multi": [ "{{WINDOW_TASK_ID}}" ], "single": [ "{{WINDOW_ID}}" ] } } }, "Priority": 0, "MaxConcurrency": "10", "MaxErrors": "5", "Name": "My-Automation-Task", "Description": "A description for my Automation task" }