文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DeleteAssetModel
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 DeleteAssetModel
。
- CLI
-
- AWS CLI
-
删除资产模型
以下
delete-asset-model
示例删除了一个风电涡轮机资产模型。aws iotsitewise delete-asset-model \ --asset-model-id
a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
输出:
{ "assetModelStatus": { "state": "DELETING" } }
有关更多信息,请参阅《AWS 物联网 SiteWise 用户指南》中的删除资产模型。
-
有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteAssetModel
中的。
-
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /** * Deletes an Asset Model with the specified ID. * * @param assetModelId the ID of the Asset Model to delete. * @return a {@link CompletableFuture} that represents a {@link DeleteAssetModelResponse} result. The calling code * can attach callbacks, then handle the result or exception by calling {@link CompletableFuture#join()} or * {@link CompletableFuture#get()}. * <p> * If any completion stage in this method throws an exception, the method logs the exception cause and keeps * it available to the calling code as a {@link CompletionException}. By calling * {@link CompletionException#getCause()}, the calling code can access the original exception. */ public CompletableFuture<DeleteAssetModelResponse> deleteAssetModelAsync(String assetModelId) { DeleteAssetModelRequest deleteAssetModelRequest = DeleteAssetModelRequest.builder() .assetModelId(assetModelId) .build(); return getAsyncClient().deleteAssetModel(deleteAssetModelRequest) .whenComplete((response, exception) -> { if (exception != null) { logger.error("Failed to delete asset model with ID:{}.", exception.getMessage()); } }); }
-
有关 API 的详细信息,请参阅 AWS SDK for Java 2.x API 参考DeleteAssetModel中的。
-
- JavaScript
-
- 适用于 JavaScript (v3) 的软件开发工具包
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 import { DeleteAssetModelCommand, IoTSiteWiseClient, } from "@aws-sdk/client-iotsitewise"; import { parseArgs } from "node:util"; /** * Delete an asset model. * @param {{ assetModelId : string }} */ export const main = async ({ assetModelId }) => { const client = new IoTSiteWiseClient({}); try { await client.send( new DeleteAssetModelCommand({ assetModelId: assetModelId, // The model id to delete. }), ); console.log("Asset model deleted successfully."); return { assetModelDeleted: true }; } catch (caught) { if (caught instanceof Error && caught.name === "ResourceNotFound") { console.warn( `${caught.message}. There was a problem deleting the asset model.`, ); } else { throw caught; } } };
-
有关 API 的详细信息,请参阅 AWS SDK for JavaScript API 参考DeleteAssetModel中的。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class IoTSitewiseWrapper: """Encapsulates AWS IoT SiteWise actions using the client interface.""" def __init__(self, iotsitewise_client: client) -> None: """ Initializes the IoTSitewiseWrapper with an AWS IoT SiteWise client. :param iotsitewise_client: A Boto3 AWS IoT SiteWise client. This client provides low-level access to AWS IoT SiteWise services. """ self.iotsitewise_client = iotsitewise_client self.entry_id = 0 # Incremented to generate unique entry IDs for batch_put_asset_property_value. @classmethod def from_client(cls) -> "IoTSitewiseWrapper": """ Creates an IoTSitewiseWrapper instance with a default AWS IoT SiteWise client. :return: An instance of IoTSitewiseWrapper initialized with the default AWS IoT SiteWise client. """ iotsitewise_client = boto3.client("iotsitewise") return cls(iotsitewise_client) def delete_asset_model(self, asset_model_id: str) -> None: """ Deletes an AWS IoT SiteWise Asset Model. :param asset_model_id: The ID of the asset model to delete. """ try: self.iotsitewise_client.delete_asset_model(assetModelId=asset_model_id) except ClientError as err: logger.error( "Error deleting asset model %s. Here's why %s", asset_model_id, err.response["Error"]["Message"], ) raise
-
有关 API 的详细信息,请参阅适用DeleteAssetModel于 Python 的AWS SDK (Boto3) API 参考。
-
- AWS CLI
-
删除资产模型
以下
delete-asset-model
示例删除了一个风电涡轮机资产模型。aws iotsitewise delete-asset-model \ --asset-model-id
a1b2c3d4-5678-90ab-cdef-11111EXAMPLE
输出:
{ "assetModelStatus": { "state": "DELETING" } }
有关更多信息,请参阅《AWS 物联网 SiteWise 用户指南》中的删除资产模型。
-
有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteAssetModel
中的。
-