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

DeleteDocument 与 Amazon SDK 或 CLI 配合使用

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

CLI
Amazon CLI

删除文档

以下 delete-document 示例删除一个 Systems Manager 文档。

aws ssm delete-document \ --name "Example"

此命令不生成任何输出。

有关更多信息,请参阅《Amazon Systems Manager 用户指南》中的创建 Systems Manager 文档

  • 有关 API 详细信息,请参阅《Amazon CLI Command Reference》中的 DeleteDocument

Java
SDK for Java 2.x
注意

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

// Deletes an AWS Systems Manager document. public static void deleteDoc(SsmClient ssmClient, String documentName) { try { DeleteDocumentRequest documentRequest = DeleteDocumentRequest.builder() .name(documentName) .build(); ssmClient.deleteDocument(documentRequest); System.out.println("The Systems Manager document was successfully deleted."); } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • 有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API Reference》中的 DeleteDocument

PowerShell
适用于 PowerShell 的工具

示例 1:此示例删除文档。如果此命令成功,则无任何输出。

Remove-SSMDocument -Name "RunShellScript"
  • 有关 API 详细信息,请参阅《Amazon Tools for PowerShell Cmdlet Reference》中的 DeleteDocument

Python
SDK for Python(Boto3)
注意

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

class DocumentWrapper: """Encapsulates AWS Systems Manager Document actions.""" def __init__(self, ssm_client): """ :param ssm_client: A Boto3 Systems Manager client. """ self.ssm_client = ssm_client self.name = None @classmethod def from_client(cls): ssm_client = boto3.client("ssm") return cls(ssm_client) def delete(self): """ Deletes an AWS Systems Manager document. """ if self.name is None: return try: self.ssm_client.delete_document(Name=self.name) print(f"Deleted document {self.name}.") self.name = None except ClientError as err: logger.error( "Couldn't delete %s. Here's why: %s: %s", self.name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • 有关 API 的详细信息,请参阅《适用于 Python 的 Amazon SDK (Boto3) API 参考》中的 DeleteDocument

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