UpdateMaintenanceWindowOR와 함께 사용 AWS SDK CLI - AWS SDK코드 예제

AWS 문서 AWS SDK SDK 예제 GitHub 리포지토리에 더 많은 예제가 있습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

UpdateMaintenanceWindowOR와 함께 사용 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

자세한 내용은 AWS Systems Manager 사용 설명서의 유지 관리 기간 업데이트 (AWS CLI) 를 참조하십시오.

Java
SDK자바 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(); }
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
Python
SDK파이썬용 (보토3)
참고

더 많은 정보가 있습니다. 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