与 AWS SDK或DeleteCertificate一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或DeleteCertificate一起使用 CLI

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

C++
SDK对于 C++
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

//! Delete a certificate. /*! \param certificateID: The ID of a certificate. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::deleteCertificate(const Aws::String &certificateID, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DeleteCertificateRequest request; request.SetCertificateId(certificateID); Aws::IoT::Model::DeleteCertificateOutcome outcome = iotClient.DeleteCertificate( request); if (outcome.IsSuccess()) { std::cout << "Successfully deleted certificate " << certificateID << std::endl; } else { std::cerr << "Error deleting certificate " << certificateID << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • 有关API详细信息,请参阅 “AWS SDK for C++ API参考 DeleteCertificate” 中的。

CLI
AWS CLI

删除设备证书

以下delete-certificate示例删除具有指定 ID 的设备证书。

aws iot delete-certificate \ --certificate-id c0c57bbc8baaf4631a9a0345c957657f5e710473e3ddbee1428d216d54d53ac9

此命令不生成任何输出。

有关更多信息,请参阅DeleteCertificateAWS 物联网API参考》。

Java
SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

/** * Deletes a certificate asynchronously. * * @param certificateArn The ARN of the certificate to delete. * * This method initiates an asynchronous request to delete a certificate. * If the deletion is successful, it prints a confirmation message. * If an exception occurs, it prints the error message. */ public void deleteCertificate(String certificateArn) { DeleteCertificateRequest certificateProviderRequest = DeleteCertificateRequest.builder() .certificateId(extractCertificateId(certificateArn)) .build(); CompletableFuture<DeleteCertificateResponse> future = getAsyncClient().deleteCertificate(certificateProviderRequest); future.whenComplete((voidResult, ex) -> { if (ex == null) { System.out.println(certificateArn + " was successfully deleted."); } else { Throwable cause = ex.getCause(); if (cause instanceof IotException) { System.err.println(((IotException) cause).awsErrorDetails().errorMessage()); } else { System.err.println("Unexpected error: " + ex.getMessage()); } } }); future.join(); }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 DeleteCertificate” 中的。

Kotlin
SDK对于 Kotlin 来说
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

suspend fun deleteCertificate(certificateArn: String) { val certificateProviderRequest = DeleteCertificateRequest { certificateId = extractCertificateId(certificateArn) } IotClient { region = "us-east-1" }.use { iotClient -> iotClient.deleteCertificate(certificateProviderRequest) println("$certificateArn was successfully deleted.") } }
  • 有关API详细信息,请参阅DeleteCertificate中的 Kotlin AWS SDK API 参考