または UpdateMaintenanceWindow で を使用する AWS SDK CLI - AWS SDK コード例

AWS Doc SDK Examples GitHub リポジトリには他にも AWS SDK例があります。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

または UpdateMaintenanceWindow で を使用する AWS SDK CLI

以下のコード例は、UpdateMaintenanceWindow の使用方法を示しています。

CLI
AWS CLI

例 1: メンテナンスウィンドウを更新するには

次の update-maintenance-window の例では、メンテナンスウィンドウの名前を更新します。

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

出力:

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

例 2: メンテナンスウィンドウを無効にするには

次の update-maintenance-window の例では、メンテナンスウィンドウを無効にします。

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

例 3: メンテナンスウィンドウを有効にするには

次の update-maintenance-window の例では、メンテナンスウィンドウを有効にします。

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

詳細については、「Systems Manager ユーザーガイド」の「メンテナンスウィンドウの更新 (AWS CLI)」を参照してください。 AWS

  • API 詳細については、「 コマンドリファレンスUpdateMaintenanceWindow」の「」を参照してください。 AWS CLI

Java
SDK for Java 2.x
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

/** * Updates an SSM maintenance window asynchronously. * * @param id The ID of the maintenance window to update. * @param name The new name for the maintenance window. * <p> * This method initiates an asynchronous request to update an SSM maintenance window. * If the request is successful, it prints a success message. * If an exception occurs, it handles the error appropriately. */ public void updateSSMMaintenanceWindow(String id, String name) throws SsmException { UpdateMaintenanceWindowRequest updateRequest = UpdateMaintenanceWindowRequest.builder() .windowId(id) .allowUnassociatedTargets(true) .duration(24) .enabled(true) .name(name) .schedule("cron(0 0 ? * MON *)") .build(); CompletableFuture<UpdateMaintenanceWindowResponse> future = getAsyncClient().updateMaintenanceWindow(updateRequest); future.whenComplete((response, ex) -> { if (response != null) { System.out.println("The SSM maintenance window was successfully updated"); } else { Throwable cause = (ex instanceof CompletionException) ? ex.getCause() : ex; if (cause instanceof SsmException) { throw new CompletionException(cause); } else { throw new RuntimeException(cause); } } }).join(); }
  • API 詳細については、「 リファレンスUpdateMaintenanceWindow」の「」を参照してください。 AWS SDK for Java 2.x API

PowerShell
のツール PowerShell

例 1: この例では、メンテナンスウィンドウの名前を更新します。

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

出力:

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

例 2: この例では、メンテナンスウィンドウを有効にします。

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

出力:

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

例 3: この例では、メンテナンスウィンドウを無効にします。

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

出力:

AllowUnassociatedTargets : False Cutoff : 1 Duration : 2 Enabled : False Name : My-Renamed-MW Schedule : cron(0 */30 * * * ? *) WindowId : mw-03eb9db42890fb82d
  • API 詳細については、「 コマンドレットリファレンスUpdateMaintenanceWindow」の「」を参照してください。 AWS Tools for PowerShell

Python
SDK for Python (Boto3)
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

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
  • API 詳細については、UpdateMaintenanceWindow「 for AWS SDK Python (Boto3) APIリファレンス」の「」を参照してください。