选择您的 Cookie 首选项

我们使用必要 Cookie 和类似工具提供我们的网站和服务。我们使用性能 Cookie 收集匿名统计数据,以便我们可以了解客户如何使用我们的网站并进行改进。必要 Cookie 无法停用,但您可以单击“自定义”或“拒绝”来拒绝性能 Cookie。

如果您同意,AWS 和经批准的第三方还将使用 Cookie 提供有用的网站功能、记住您的首选项并显示相关内容,包括相关广告。要接受或拒绝所有非必要 Cookie,请单击“接受”或“拒绝”。要做出更详细的选择,请单击“自定义”。

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

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

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

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

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

DetachThingPrincipal与 AWS SDK 或 CLI 配合使用

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

C++
SDK for C++
注意

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

//! Detach a principal from an AWS IoT thing. /*! \param principal: A principal to detach. \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::detachThingPrincipal(const Aws::String &principal, const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DetachThingPrincipalRequest detachThingPrincipalRequest; detachThingPrincipalRequest.SetThingName(thingName); detachThingPrincipalRequest.SetPrincipal(principal); Aws::IoT::Model::DetachThingPrincipalOutcome outcome = iotClient.DetachThingPrincipal( detachThingPrincipalRequest); if (outcome.IsSuccess()) { std::cout << "Successfully detached principal " << principal << " from thing " << thingName << std::endl; } else { std::cerr << "Failed to detach principal " << principal << " from thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
CLI
AWS CLI

将证书/主体与事物分离

以下 detach-thing-principal 示例从指定事物中移除代表一个主体的证书。

aws iot detach-thing-principal \ --thing-name "MyLightBulb" \ --principal "arn:aws:iot:us-west-2:123456789012:cert/604c48437a57b7d5fc5d137c5be75011c6ee67c9a6943683a1acb4b1626bac36"

此命令不生成任何输出。

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

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

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

/** * Detaches a principal (certificate) from an IoT Thing asynchronously. * * @param thingName The name of the IoT Thing. * @param certificateArn The ARN of the certificate to detach. * * This method initiates an asynchronous request to detach a certificate from an IoT Thing. * If the detachment is successful, it prints a confirmation message. * If an exception occurs, it prints the error message. */ public void detachThingPrincipal(String thingName, String certificateArn) { DetachThingPrincipalRequest thingPrincipalRequest = DetachThingPrincipalRequest.builder() .principal(certificateArn) .thingName(thingName) .build(); CompletableFuture<DetachThingPrincipalResponse> future = getAsyncClient().detachThingPrincipal(thingPrincipalRequest); future.whenComplete((voidResult, ex) -> { if (ex == null) { System.out.println(certificateArn + " was successfully removed from " + 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 参考DetachThingPrincipal中的。

Kotlin
适用于 Kotlin 的 SDK
注意

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

suspend fun detachThingPrincipal( thingNameVal: String, certificateArn: String, ) { val thingPrincipalRequest = DetachThingPrincipalRequest { principal = certificateArn thingName = thingNameVal } IotClient { region = "us-east-1" }.use { iotClient -> iotClient.detachThingPrincipal(thingPrincipalRequest) println("$certificateArn was successfully removed from $thingNameVal") } }
  • 有关 API 的详细信息,请参阅适用DetachThingPrincipal于 K otlin 的AWS SDK API 参考

SDK for C++
注意

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

//! Detach a principal from an AWS IoT thing. /*! \param principal: A principal to detach. \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::detachThingPrincipal(const Aws::String &principal, const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DetachThingPrincipalRequest detachThingPrincipalRequest; detachThingPrincipalRequest.SetThingName(thingName); detachThingPrincipalRequest.SetPrincipal(principal); Aws::IoT::Model::DetachThingPrincipalOutcome outcome = iotClient.DetachThingPrincipal( detachThingPrincipalRequest); if (outcome.IsSuccess()) { std::cout << "Successfully detached principal " << principal << " from thing " << thingName << std::endl; } else { std::cerr << "Failed to detach principal " << principal << " from thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
隐私网站条款Cookie 首选项
© 2025, Amazon Web Services, Inc. 或其附属公司。保留所有权利。