Use UpdateMaintenanceWindow with an Amazon SDK or CLI - Amazon Systems Manager
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use UpdateMaintenanceWindow with an Amazon SDK or CLI

The following code examples show how to use UpdateMaintenanceWindow.

CLI
Amazon CLI

Example 1: To update a maintenance window

The following update-maintenance-window example updates the name of a maintenance window.

aws ssm update-maintenance-window \ --window-id "mw-1a2b3c4d5e6f7g8h9" \ --name "My-Renamed-MW"

Output:

{ "Cutoff": 1, "Name": "My-Renamed-MW", "Schedule": "cron(0 16 ? * TUE *)", "Enabled": true, "AllowUnassociatedTargets": true, "WindowId": "mw-1a2b3c4d5e6f7g8h9", "Duration": 4 }

Example 2: To disable a maintenance window

The following update-maintenance-window example disables a maintenance window.

aws ssm update-maintenance-window \ --window-id "mw-1a2b3c4d5e6f7g8h9" \ --no-enabled

Example 3: To enable a maintenance window

The following update-maintenance-window example enables a maintenance window.

aws ssm update-maintenance-window \ --window-id "mw-1a2b3c4d5e6f7g8h9" \ --enabled

For more information, see Update a Maintenance Window (Amazon CLI) in the Amazon Systems Manager User Guide.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

// Update the maintenance window schedule public static void updateSSMMaintenanceWindow(SsmClient ssmClient, String id, String name) { try { UpdateMaintenanceWindowRequest updateRequest = UpdateMaintenanceWindowRequest.builder() .windowId(id) .allowUnassociatedTargets(true) .duration(24) .enabled(true) .name(name) .schedule("cron(0 0 ? * MON *)") .build(); ssmClient.updateMaintenanceWindow(updateRequest); System.out.println("The Systems Manager maintenance window was successfully updated."); } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } }
PowerShell
Tools for PowerShell

Example 1: This example updates the name of a maintenance window.

Update-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d" -Name "My-Renamed-MW"

Output:

AllowUnassociatedTargets : False Cutoff : 1 Duration : 2 Enabled : True Name : My-Renamed-MW Schedule : cron(0 */30 * * * ? *) WindowId : mw-03eb9db42890fb82d

Example 2: This example enables a maintenance window.

Update-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d" -Enabled $true

Output:

AllowUnassociatedTargets : False Cutoff : 1 Duration : 2 Enabled : True Name : My-Renamed-MW Schedule : cron(0 */30 * * * ? *) WindowId : mw-03eb9db42890fb82d

Example 3: This example disables a maintenance window.

Update-SSMMaintenanceWindow -WindowId "mw-03eb9db42890fb82d" -Enabled $false

Output:

AllowUnassociatedTargets : False Cutoff : 1 Duration : 2 Enabled : False Name : My-Renamed-MW Schedule : cron(0 */30 * * * ? *) WindowId : mw-03eb9db42890fb82d
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

class MaintenanceWindowWrapper: """Encapsulates AWS Systems Manager maintenance window actions.""" def __init__(self, ssm_client): """ :param ssm_client: A Boto3 Systems Manager client. """ self.ssm_client = ssm_client self.window_id = None self.name = None @classmethod def from_client(cls): ssm_client = boto3.client("ssm") return cls(ssm_client) def update( self, name, enabled, schedule, duration, cutoff, allow_unassociated_targets ): """ Update an AWS Systems Manager maintenance window. :param name: The name of the maintenance window. :param enabled: Whether the maintenance window is enabled to run on managed nodes. :param schedule: The schedule of the maintenance window. :param duration: The duration of the maintenance window. :param cutoff: The cutoff time of the maintenance window. :param allow_unassociated_targets: Allow the maintenance window to run on managed nodes, even if you haven't registered those nodes as targets. """ try: self.ssm_client.update_maintenance_window( WindowId=self.window_id, Name=name, Enabled=enabled, Schedule=schedule, Duration=duration, Cutoff=cutoff, AllowUnassociatedTargets=allow_unassociated_targets, ) self.name = name logger.info("Updated maintenance window %s.", self.window_id) except ParamValidationError as error: logger.error( "Parameter validation error when trying to update maintenance window %s. Here's why: %s", self.window_id, error, ) raise except ClientError as err: logger.error( "Couldn't update maintenance window %s. Here's why: %s: %s", self.name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise

For a complete list of Amazon SDK developer guides and code examples, see Using Systems Manager with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.