搭DeleteCollection配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DeleteCollection配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用DeleteCollection

如需更多資訊,請參閱刪除集合

.NET
AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 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}"); } }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考DeleteCollection中的。

CLI
AWS CLI

若要刪除商品系列

下面的delete-collection命令刪除指定的集合。

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

輸出:

{ "StatusCode": 200 }

如需詳細資訊,請參閱 Amazon Rekognition 開發人員指南中的刪除集合

  • 如需詳API細資訊,請參閱AWS CLI 指令參考DeleteCollection中的。

Java
SDK對於爪哇 2.x
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 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(); } 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); } } }
  • 如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考DeleteCollection中的。

Kotlin
SDK對於科特林
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

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}") } }
  • 有API關詳細資訊,請參閱DeleteCollectionAWS SDK的以取得 Kotlin API 的參考資料

Python
SDK對於 Python(肉毒桿菌 3)
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 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
  • 如需詳API細資訊,請參閱DeleteCollectionAWS SDK的〈〉以取得 Python (Boto3) API 參考資料。