Usar DeletePortal com o AWS SDK ou a CLI - Exemplos de código do AWS SDK

Há mais exemplos do AWS SDK disponíveis no repositório do GitHub Documento de Exemplos do AWS SDK.

Usar DeletePortal com o AWS SDK ou a CLI

Os exemplos de código a seguir mostram como usar o DeletePortal.

CLI
AWS CLI

Para excluir um portal

O exemplo delete-portal a seguir exclui um portal da web para uma empresa de parques eólicos.

aws iotsitewise delete-portal \ --portal-id a1b2c3d4-5678-90ab-cdef-aaaaaEXAMPLE

Saída:

{ "portalStatus": { "state": "DELETING" } }

Para obter mais informações, consulte Excluir um portal no Guia do usuário do AWS IoT SiteWise.

  • Para ver detalhes da API, consulte DeletePortal na Referência de comandos da AWS CLI.

Java
SDK para Java 2.x
nota

Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

/** * Deletes a portal. * * @param portalId the ID of the portal to be deleted. * @return a {@link CompletableFuture} that represents a {@link DeletePortalResponse}. 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<DeletePortalResponse> deletePortalAsync(String portalId) { DeletePortalRequest deletePortalRequest = DeletePortalRequest.builder() .portalId(portalId) .build(); return getAsyncClient().deletePortal(deletePortalRequest) .whenComplete((response, exception) -> { if (exception != null) { logger.error("Failed to delete portal with ID: {}. Error: {}", portalId, exception.getCause().getMessage()); } }); }
  • Consulte detalhes da API em DeletePortal na Referência de API do AWS SDK for Java 2.x.

JavaScript
SDK para JavaScript (v3)
nota

Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

import { DeletePortalCommand, IoTSiteWiseClient, } from "@aws-sdk/client-iotsitewise"; import { parseArgs } from "node:util"; /** * List asset models. * @param {{ portalId : string }} */ export const main = async ({ portalId }) => { const client = new IoTSiteWiseClient({}); try { await client.send( new DeletePortalCommand({ portalId: portalId, // The id of the portal. }), ); console.log("Portal deleted successfully."); return { portalDeleted: true }; } catch (caught) { if (caught instanceof Error && caught.name === "ResourceNotFound") { console.warn( `${caught.message}. There was a problem deleting the portal. Please check the portal id.`, ); } else { throw caught; } } };
  • Consulte detalhes da API em DeletePortal na Referência de API do AWS SDK para JavaScript.

Python
SDK para Python (Boto3).
nota

Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

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_portal(self, portal_id: str) -> None: """ Deletes an AWS IoT SiteWise Portal. :param portal_id: The ID of the portal to delete. """ try: self.iotsitewise_client.delete_portal(portalId=portal_id) except ClientError as err: if err.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Portal %s does not exist.", portal_id) else: logger.error( "Error deleting portal %s. Here's why %s", portal_id, err.response["Error"]["Message"], ) raise
  • Consulte detalhes da API em DeletePortal na Referência de API do AWS SDK para Python (Boto3).