将 DeleteMaintenanceWindow 与 Amazon SDK 或 CLI 配合使用 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

DeleteMaintenanceWindow 与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 DeleteMaintenanceWindow

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

CLI
Amazon CLI

删除维护时段

delete-maintenance-window 示例删除指定的维护时段。

aws ssm delete-maintenance-window \ --window-id "mw-1a2b3c4d5e6f7g8h9"

输出:

{ "WindowId":"mw-1a2b3c4d5e6f7g8h9" }

有关更多信息,请参阅《Amazon Systems Manager 用户指南》中的删除维护时段(Amazon CLI)

Java
SDK for Java 2.x
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void deleteMaintenanceWindow(SsmClient ssmClient, String winId) { try { DeleteMaintenanceWindowRequest windowRequest = DeleteMaintenanceWindowRequest.builder() .windowId(winId) .build(); ssmClient.deleteMaintenanceWindow(windowRequest); System.out.println("The maintenance window was successfully deleted."); } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } }
PowerShell
适用于 PowerShell 的工具

示例 1:此示例删除维护时段。

Remove-SSMMaintenanceWindow -WindowId "mw-06d59c1a07c022145"

输出:

mw-06d59c1a07c022145
  • 有关 API 详细信息,请参阅《Amazon Tools for PowerShell Cmdlet Reference》中的 DeleteMaintenanceWindow

Python
SDK for Python(Boto3)
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

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 delete(self): """ Delete the associated AWS Systems Manager maintenance window. """ if self.window_id is None: return try: self.ssm_client.delete_maintenance_window(WindowId=self.window_id) logger.info("Deleted maintenance window %s.", self.window_id) print(f"Deleted maintenance window {self.name}") self.window_id = None except ClientError as err: logger.error( "Couldn't delete maintenance window %s. Here's why: %s: %s", self.window_id, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • 有关 API 详细信息,请参阅《适用于 Python 的 Amazon SDK (Boto3) API 参考》中的 DeleteMaintenanceWindow

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将 Systems Manager 与 Amazon SDK 配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。