Uso de DeleteCollection con un SDK de AWS o la CLI - Ejemplos de código de AWS SDK

Hay más ejemplos de AWS SDK disponibles en el repositorio de GitHub de ejemplos de AWS SDK de documentos.

Uso de DeleteCollection con un SDK de AWS o la CLI

Los siguientes ejemplos de código muestran cómo utilizar DeleteCollection.

Para obtener información, consulte Eliminación de una colección.

.NET
SDK para .NET
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

using System; using System.Threading.Tasks; using Amazon.Rekognition; using Amazon.Rekognition.Model; /// <summary> /// Uses the Amazon Rekognition Service to delete an existing collection. /// </summary> public class DeleteCollection { public static async Task Main() { var rekognitionClient = new AmazonRekognitionClient(); string collectionId = "MyCollection"; Console.WriteLine("Deleting collection: " + collectionId); var deleteCollectionRequest = new DeleteCollectionRequest() { CollectionId = collectionId, }; var deleteCollectionResponse = await rekognitionClient.DeleteCollectionAsync(deleteCollectionRequest); Console.WriteLine($"{collectionId}: {deleteCollectionResponse.StatusCode}"); } }
  • Para obtener información sobre la API, consulte DeleteCollection en la Referencia de API de AWS SDK para .NET.

CLI
AWS CLI

Eliminación de una colección

El siguiente comando delete-collection elimina la colección especificada.

aws rekognition delete-collection \ --collection-id MyCollection

Salida:

{ "StatusCode": 200 }

Para obtener más información, consulte Eliminación de una colección en la Guía para desarrolladores de Amazon Rekognition.

  • Para obtener información sobre la API, consulte DeleteCollection en la Referencia de comandos de la AWS CLI.

Java
SDK para Java 2.x
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.DeleteCollectionRequest; import software.amazon.awssdk.services.rekognition.model.DeleteCollectionResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DeleteCollection { public static void main(String[] args) { final String usage = """ Usage: <collectionId>\s Where: collectionId - The id of the collection to delete.\s """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String collectionId = args[0]; Region region = Region.US_EAST_1; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .build(); System.out.println("Deleting collection: " + collectionId); deleteMyCollection(rekClient, collectionId); rekClient.close(); } /** * Deletes an Amazon Rekognition collection. * * @param rekClient An instance of the {@link RekognitionClient} class, which is used to interact with the Amazon Rekognition service. * @param collectionId The ID of the collection to be deleted. */ public static void deleteMyCollection(RekognitionClient rekClient, String collectionId) { try { DeleteCollectionRequest deleteCollectionRequest = DeleteCollectionRequest.builder() .collectionId(collectionId) .build(); DeleteCollectionResponse deleteCollectionResponse = rekClient.deleteCollection(deleteCollectionRequest); System.out.println(collectionId + ": " + deleteCollectionResponse.statusCode().toString()); } catch (RekognitionException e) { System.out.println(e.getMessage()); System.exit(1); } } }
  • Para obtener información sobre la API, consulte DeleteCollection en la Referencia de API de AWS SDK for Java 2.x.

Kotlin
SDK para Kotlin
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

suspend fun deleteMyCollection(collectionIdVal: String) { val request = DeleteCollectionRequest { collectionId = collectionIdVal } RekognitionClient.fromEnvironment { region = "us-east-1" }.use { rekClient -> val response = rekClient.deleteCollection(request) println("The collectionId status is ${response.statusCode}") } }
  • Para obtener información acerca de la API, consulte DeleteCollection en la Referencia de la API del SDK de AWS para Kotlin.

Python
SDK para Python (Boto3)
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

class RekognitionCollection: """ Encapsulates an Amazon Rekognition collection. This class is a thin wrapper around parts of the Boto3 Amazon Rekognition API. """ def __init__(self, collection, rekognition_client): """ Initializes a collection object. :param collection: Collection data in the format returned by a call to create_collection. :param rekognition_client: A Boto3 Rekognition client. """ self.collection_id = collection["CollectionId"] self.collection_arn, self.face_count, self.created = self._unpack_collection( collection ) self.rekognition_client = rekognition_client @staticmethod def _unpack_collection(collection): """ Unpacks optional parts of a collection that can be returned by describe_collection. :param collection: The collection data. :return: A tuple of the data in the collection. """ return ( collection.get("CollectionArn"), collection.get("FaceCount", 0), collection.get("CreationTimestamp"), ) def delete_collection(self): """ Deletes the collection. """ try: self.rekognition_client.delete_collection(CollectionId=self.collection_id) logger.info("Deleted collection %s.", self.collection_id) self.collection_id = None except ClientError: logger.exception("Couldn't delete collection %s.", self.collection_id) raise
  • Para obtener detalles sobre la API, consulte DeleteCollection en la Referencia de la API del SDK de AWS para Python (Boto3).