Use DeleteDocument com um AWS SDK ou CLI - AWS SDK Exemplos de código

Há mais AWS SDK exemplos disponíveis no GitHub repositório AWS Doc SDK Examples.

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Use DeleteDocument com um AWS SDK ou CLI

Os exemplos de códigos a seguir mostram como usar DeleteDocument.

CLI
AWS CLI

Para excluir um documento

O exemplo de delete-document a seguir exclui um documento do Systems Manager.

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

Este comando não produz saída.

Para obter mais informações, consulte Criar documentos do Systems Manager no Guia do usuário do AWS Systems Manager.

  • Para API obter detalhes, consulte DeleteDocumentna Referência de AWS CLI Comandos.

Java
SDKpara Java 2.x
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

/** * Deletes an AWS SSM document asynchronously. * * @param documentName The name of the document to delete. * <p> * This method initiates an asynchronous request to delete an SSM document. * If an exception occurs, it handles the error appropriately. */ public void deleteDoc(String documentName) { DeleteDocumentRequest documentRequest = DeleteDocumentRequest.builder() .name(documentName) .build(); CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { getAsyncClient().deleteDocument(documentRequest) .thenAccept(response -> { System.out.println("The SSM document was successfully deleted."); }) .exceptionally(ex -> { throw new CompletionException(ex); }).join(); }).exceptionally(ex -> { Throwable cause = (ex instanceof CompletionException) ? ex.getCause() : ex; if (cause instanceof SsmException) { throw new RuntimeException("SSM error: " + cause.getMessage(), cause); } else { throw new RuntimeException("Unexpected error: " + cause.getMessage(), cause); } }); try { future.join(); } catch (CompletionException ex) { throw ex.getCause() instanceof RuntimeException ? (RuntimeException) ex.getCause() : ex; } }
  • Para API obter detalhes, consulte DeleteDocumentem AWS SDK for Java 2.x APIReferência.

PowerShell
Ferramentas para PowerShell

Exemplo 1: esse exemplo exclui um documento. Não haverá saída se o comando for bem-sucedido.

Remove-SSMDocument -Name "RunShellScript"
  • Para API obter detalhes, consulte DeleteDocumentem Referência de AWS Tools for PowerShell cmdlet.

Python
SDKpara Python (Boto3)
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

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
  • Para API obter detalhes, consulte a DeleteDocumentReferência AWS SDK do Python (Boto3). API