Usar DeleteTracker com um SDK da AWS - 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 DeleteTracker com um SDK da AWS

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

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 tracker with the specified name. * * @param trackerName the name of the tracker to be deleted * @return a {@link CompletableFuture} that completes when the tracker has been deleted * @throws CompletionException if an error occurs while deleting the tracker * - if the tracker was not found, a {@link ResourceNotFoundException} is thrown wrapped in the CompletionException * - if any other error occurs, a generic CompletionException is thrown with the error message */ public CompletableFuture<Void> deleteTracker(String trackerName) { DeleteTrackerRequest trackerRequest = DeleteTrackerRequest.builder() .trackerName(trackerName) .build(); return getClient().deleteTracker(trackerRequest) .whenComplete((response, exception) -> { if (exception != null) { Throwable cause = exception.getCause(); if (cause instanceof ResourceNotFoundException) { throw new CompletionException("The tracker was not found.", cause); } throw new CompletionException("Failed to delete the tracker: " + exception.getMessage(), exception); } logger.info("The tracker {} was deleted.", trackerName); }) .thenApply(response -> null); // Ensures CompletableFuture<Void> }
  • Consulte detalhes da API em DeleteTracker 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 { fileURLToPath } from "node:url"; import { DeleteTrackerCommand, LocationClient, ResourceNotFoundException, } from "@aws-sdk/client-location"; import data from "./inputs.json" with { type: "json" }; const region = "eu-west-1"; export const main = async () => { const deleteTrackerParams = { TrackerName: `${data.inputs.trackerName}`, }; try { const locationClient = new LocationClient({ region: region }); const command = new DeleteTrackerCommand(deleteTrackerParams); const response = await locationClient.send(command); console.log("Tracker deleted."); } catch (caught) { if (caught instanceof ResourceNotFoundException) { console.error(`${data.inputs.trackerName} tracker not found.`); return; } } };
  • Consulte detalhes da API em DeleteTracker na Referência de API do AWS SDK para JavaScript.

Kotlin
SDK para Kotlin
nota

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

/** * Deletes a tracker with the specified name. * @param trackerName the name of the tracker to be deleted */ suspend fun deleteTracker(trackerName: String) { val trackerRequest = DeleteTrackerRequest { this.trackerName = trackerName } LocationClient { region = "us-east-1" }.use { client -> client.deleteTracker(trackerRequest) println("The tracker $trackerName was deleted.") } }
  • Consulte detalhes da API em DeleteTracker na Referência de API do AWS SDK para Kotlin.