Usar DeleteCertificate com o AWS SDK ou a CLI - Exemplos de código do AWS SDK

Há mais exemplos do AWS SDK disponíveis no repositório do GitHub Documento de Exemplos do AWS SDK.

Usar DeleteCertificate com o AWS SDK ou a CLI

Os exemplos de código a seguir mostram como usar o DeleteCertificate.

Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação em contexto no seguinte exemplo de código:

C++
SDK para C++
nota

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

//! Delete an AWS Certificate Manager (ACM) certificate. /*! \param certificateArn: The Amazon Resource Name (ARN) of a certificate. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::ACM::deleteCertificate(const Aws::String &certificateArn, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::ACM::ACMClient acmClient(clientConfiguration); Aws::ACM::Model::DeleteCertificateRequest request; request.WithCertificateArn(certificateArn); Aws::ACM::Model::DeleteCertificateOutcome outcome = acmClient.DeleteCertificate(request); if (!outcome.IsSuccess()) { std::cerr << "Error: DeleteCertificate: " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Success: The certificate with the ARN '" << certificateArn << "' is deleted." << std::endl; } return outcome.IsSuccess(); }
  • Consulte detalhes da API em DeleteCertificate na Referência de API do AWS SDK para C++.

CLI
AWS CLI

Como excluir um certificado do ACM da sua conta

O seguinte comando delete-certificate exclui o certificado com o ARN especificado:

aws acm delete-certificate --certificate-arn arn:aws:acm:region:account:certificate/12345678-1234-1234-1234-123456789012
  • Consulte detalhes da API em DeleteCertificate na Referência de comandos da AWS CLI.

Java
SDK para Java 2.x
nota

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

/** * Before running this Java V2 code example, set up your development * environment, including your credentials. * <p> * For more information, see the following documentation topic: * <p> * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DeleteCert { public static void main(String[] args) { final String usage = """ Usage: <certArn> Where: certArn - the ARN of the certificate. """; if (args.length != 1) { System.out.println(usage); return; } String certArn = args[0]; deleteCertificate(certArn); } /** * Deletes an SSL/TLS certificate from the AWS Certificate Manager (ACM). * * @param certArn the Amazon Resource Name (ARN) of the certificate to be deleted */ public static void deleteCertificate( String certArn) { AcmClient acmClient = AcmClient.create(); DeleteCertificateRequest request = DeleteCertificateRequest.builder() .certificateArn(certArn) .build(); try { acmClient.deleteCertificate(request); System.out.println("The certificate was deleted"); } catch (AcmException e) { System.out.println(e.getMessage()); } } }
  • Consulte detalhes da API em DeleteCertificate na Referência de API do AWS SDK for Java 2.x.

PowerShell
Ferramentas para PowerShell V4

Exemplo 1: exclui o certificado identificado pelo ARN fornecido e pela chave privada associada. O cmdlet solicitará confirmação antes de prosseguir. Adicione a opção -Force para ignorar a confirmação.

Remove-ACMCertificate -CertificateArn "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012"
  • Consulte detalhes da API em DeleteCertificate na Referência de cmdlet do Ferramentas da AWS para PowerShell (V4).

Ferramentas para PowerShell V5

Exemplo 1: exclui o certificado identificado pelo ARN fornecido e pela chave privada associada. O cmdlet solicitará confirmação antes de prosseguir. Adicione a opção -Force para ignorar a confirmação.

Remove-ACMCertificate -CertificateArn "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012"
  • Consulte detalhes da API em DeleteCertificate na Referência de cmdlet do Ferramentas da AWS para PowerShell (V5).

Python
SDK para Python (Boto3).
nota

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

class AcmCertificate: """ Encapsulates ACM functions. """ def __init__(self, acm_client): """ :param acm_client: A Boto3 ACM client. """ self.acm_client = acm_client def remove(self, certificate_arn): """ Removes a certificate. :param certificate_arn: The ARN of the certificate to remove. """ try: self.acm_client.delete_certificate(CertificateArn=certificate_arn) logger.info("Removed certificate %s.", certificate_arn) except ClientError: logger.exception("Couldn't remove certificate %s.", certificate_arn) raise
  • Consulte detalhes da API em DeleteCertificate na Referência da API AWS SDK para Python (Boto3).