DeleteCollectionÚselo con un AWS SDKo CLI - Amazon Rekognition

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

DeleteCollectionÚselo con un AWS SDKo CLI

En los siguientes ejemplos de código, se muestra cómo utilizar DeleteCollection.

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

.NET
AWS SDK for .NET
nota

Hay más información GitHub. Consulta el ejemplo completo y aprende a configurarlo y a ejecutarlo en AWS Repositorio de ejemplos de código.

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 API obtener más información, consulte DeleteCollectionen AWS SDK for .NET APIReferencia.

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 API obtener más información, consulte DeleteCollectionen AWS CLI Referencia de comandos.

Java
SDKpara Java 2.x
nota

Hay más información. GitHub Consulta el ejemplo completo y aprende a configurarlo y a ejecutarlo en AWS Repositorio de ejemplos de código.

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(); } 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 API obtener más información, consulte DeleteCollectionen AWS SDK for Java 2.x APIReferencia.

Kotlin
SDKpara Kotlin
nota

Hay más información. GitHub Consulta el ejemplo completo y aprende a configurarlo y a ejecutarlo en AWS Repositorio de ejemplos de código.

suspend fun deleteMyCollection(collectionIdVal: String) { val request = DeleteCollectionRequest { collectionId = collectionIdVal } RekognitionClient { region = "us-east-1" }.use { rekClient -> val response = rekClient.deleteCollection(request) println("The collectionId status is ${response.statusCode}") } }
  • Para API obtener más información, consulte DeleteCollectionen AWS SDKcomo API referencia sobre Kotlin.

Python
SDKpara Python (Boto3)
nota

Hay más información. GitHub Consulta el ejemplo completo y aprende a configurarlo y a ejecutarlo en AWS Repositorio de ejemplos de código.

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 API obtener más información, consulte DeleteCollectionen AWS SDKpara referencia de Python (Boto3). API

Para obtener una lista completa de AWS SDKguías para desarrolladores y ejemplos de código, consulteUso de Rekognition con un AWS SDK. En este tema también se incluye información sobre cómo empezar y detalles sobre SDK las versiones anteriores.