D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples GitHub .
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Utilisation DeleteGeofenceCollection avec un AWS SDK
Les exemples de code suivants illustrent comment utiliser DeleteGeofenceCollection.
Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :
- Java
-
- SDK pour Java 2.x
-
/**
* Deletes a geofence collection asynchronously.
*
* @param collectionName the name of the geofence collection to be deleted
* @return a {@link CompletableFuture} that completes when the geofence collection has been deleted
*/
public CompletableFuture<Void> deleteGeofenceCollectionAsync(String collectionName) {
DeleteGeofenceCollectionRequest collectionRequest = DeleteGeofenceCollectionRequest.builder()
.collectionName(collectionName)
.build();
return getClient().deleteGeofenceCollection(collectionRequest)
.whenComplete((response, exception) -> {
if (exception != null) {
Throwable cause = exception.getCause();
if (cause instanceof ResourceNotFoundException) {
throw new CompletionException("The requested geofence collection was not found.", cause);
}
throw new CompletionException("Failed to delete geofence collection: " + exception.getMessage(), exception);
}
logger.info("The geofence collection {} was deleted.", collectionName);
})
.thenApply(response -> null);
}
- JavaScript
-
- SDK pour JavaScript (v3)
-
import { fileURLToPath } from "node:url";
import {
DeleteGeofenceCollectionCommand,
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 deleteGeofenceCollParams = {
CollectionName: `${data.inputs.collectionName}`,
};
const locationClient = new LocationClient({ region: region });
try {
const command = new DeleteGeofenceCollectionCommand(
deleteGeofenceCollParams,
);
const response = await locationClient.send(command);
console.log("Collection deleted.");
} catch (caught) {
if (caught instanceof ResourceNotFoundException) {
console.error(
`${data.inputs.collectionName} Geofence collection not found.`,
);
return;
}
}
};
- Kotlin
-
- SDK pour Kotlin
-
/**
* Deletes a geofence collection.
*
* @param collectionName the name of the geofence collection to be deleted
* @return a {@link CompletableFuture} that completes when the geofence collection has been deleted
*/
suspend fun deleteGeofenceCollection(collectionName: String) {
val collectionRequest = DeleteGeofenceCollectionRequest {
this.collectionName = collectionName
}
LocationClient.fromEnvironment { region = "us-east-1" }.use { client ->
client.deleteGeofenceCollection(collectionRequest)
println("The geofence collection $collectionName was deleted.")
}
}