文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DeleteGateway
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DeleteGateway
。
- CLI
-
- AWS CLI
-
刪除閘道
下列
delete-gateway
範例會刪除閘道。aws iotsitewise delete-gateway \ --gateway-id
a1b2c3d4-5678-90ab-cdef-1a1a1EXAMPLE
此命令不會產生輸出。
如需詳細資訊,請參閱 AWS IoT SiteWise 使用者指南中的使用閘道擷取資料。
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteGateway
。
-
- Java
-
- SDK for Java 2.x
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** * Deletes the specified gateway. * * @param gatewayId the ID of the gateway to delete. * @return a {@link CompletableFuture} that represents a {@link DeleteGatewayResponse} 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<DeleteGatewayResponse> deleteGatewayAsync(String gatewayId) { DeleteGatewayRequest deleteGatewayRequest = DeleteGatewayRequest.builder() .gatewayId(gatewayId) .build(); return getAsyncClient().deleteGateway(deleteGatewayRequest) .whenComplete((response, exception) -> { if (exception != null) { logger.error("Failed to delete gateway: {}", exception.getCause().getMessage()); } }); }
-
如需 API 詳細資訊,請參閱 AWS SDK for Java 2.x API 參考中的 DeleteGateway。
-
- JavaScript
-
- SDK for JavaScript (v3)
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import { DeleteGatewayCommand, IoTSiteWiseClient, } from "@aws-sdk/client-iotsitewise"; import { parseArgs } from "node:util"; /** * Create an SSM document. * @param {{ content: string, name: string, documentType?: DocumentType }} */ export const main = async ({ gatewayId }) => { const client = new IoTSiteWiseClient({}); try { await client.send( new DeleteGatewayCommand({ gatewayId: gatewayId, // The ID of the Gateway to describe. }), ); console.log("Gateway deleted successfully."); return { gatewayDeleted: true }; } catch (caught) { if (caught instanceof Error && caught.name === "ResourceNotFound") { console.warn( `${caught.message}. The Gateway could not be found. Please check the Gateway Id.`, ); } else { throw caught; } } };
-
如需 API 詳細資訊,請參閱 AWS SDK for JavaScript API 參考中的 DeleteGateway。
-
- Python
-
- SDK for Python (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_gateway(self, gateway_id: str) -> None: """ Deletes an AWS IoT SiteWise Gateway. :param gateway_id: The ID of the gateway to delete. """ try: self.iotsitewise_client.delete_gateway(gatewayId=gateway_id) except ClientError as err: if err.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Gateway %s does not exist.", gateway_id) else: logger.error( "Error deleting gateway %s. Here's why %s", gateway_id, err.response["Error"]["Message"], ) raise
-
如需 API 詳細資訊,請參閱 SDK AWS for Python (Boto3) API 參考中的 DeleteGateway。
-
- AWS CLI
-
刪除閘道
下列
delete-gateway
範例會刪除閘道。aws iotsitewise delete-gateway \ --gateway-id
a1b2c3d4-5678-90ab-cdef-1a1a1EXAMPLE
此命令不會產生輸出。
如需詳細資訊,請參閱 AWS IoT SiteWise 使用者指南中的使用閘道擷取資料。
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteGateway
。
-