DeleteThing与 AWS SDK 或 CLI 配合使用 - AWS SDK 代码示例

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

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

DeleteThing与 AWS SDK 或 CLI 配合使用

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

C++
SDK for C++
注意

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

//! Delete an AWS IoT thing. /*! \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::deleteThing(const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DeleteThingRequest request; request.SetThingName(thingName); const auto outcome = iotClient.DeleteThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully deleted thing " << thingName << std::endl; } else { std::cerr << "Error deleting thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • 有关 API 的详细信息,请参阅 AWS SDK for C++ API 参考DeleteThing中的。

CLI
AWS CLI

显示有关事物的详细信息

以下delete-thing示例从您 AWS 账户的 AWS IoT 注册表中删除一个事物。

aws iot 删除-thing-thing-name “” FourthBulb

此命令不生成任何输出。

有关更多信息,请参阅《AWS IoT 开发人员指南》中的如何使用注册表管理事物

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteThing中的。

Java
适用于 Java 的 SDK 2.x
注意

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

/** * Deletes an IoT Thing asynchronously. * * @param thingName The name of the IoT Thing to delete. * * This method initiates an asynchronous request to delete an IoT Thing. * If the deletion is successful, it prints a confirmation message. * If an exception occurs, it prints the error message. */ public void deleteIoTThing(String thingName) { DeleteThingRequest deleteThingRequest = DeleteThingRequest.builder() .thingName(thingName) .build(); CompletableFuture<DeleteThingResponse> future = getAsyncClient().deleteThing(deleteThingRequest); future.whenComplete((voidResult, ex) -> { if (ex == null) { System.out.println("Deleted Thing " + thingName); } 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 参考DeleteThing中的。

Kotlin
适用于 Kotlin 的 SDK
注意

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

suspend fun deleteIoTThing(thingNameVal: String) { val deleteThingRequest = DeleteThingRequest { thingName = thingNameVal } IotClient { region = "us-east-1" }.use { iotClient -> iotClient.deleteThing(deleteThingRequest) println("Deleted $thingNameVal") } }
  • 有关 API 的详细信息,请参阅适用DeleteThing于 K otlin 的AWS SDK API 参考