You can use the ListCollections operation to list the collections in the region that you are using.
For more information, see Managing a collection.
To list collections (SDK)
-
If you haven't already:
-
Create or update a user with
AmazonRekognitionFullAccess
permissions. For more information, see Step 1: Set up an AWS account and create a User. -
Install and configure the AWS CLI and the AWS SDKs. For more information, see Step 2: Set up the AWS CLI and AWS SDKs.
-
-
Use the following examples to call the
ListCollections
operation.The following example lists the collections in the current region.
//Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) package aws.example.rekognition.image; import java.util.List; import com.amazonaws.services.rekognition.AmazonRekognition; import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; import com.amazonaws.services.rekognition.model.ListCollectionsRequest; import com.amazonaws.services.rekognition.model.ListCollectionsResult; public class ListCollections { public static void main(String[] args) throws Exception { AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient(); System.out.println("Listing collections"); int limit = 10; ListCollectionsResult listCollectionsResult = null; String paginationToken = null; do { if (listCollectionsResult != null) { paginationToken = listCollectionsResult.getNextToken(); } ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest() .withMaxResults(limit) .withNextToken(paginationToken); listCollectionsResult=amazonRekognition.listCollections(listCollectionsRequest); List < String > collectionIds = listCollectionsResult.getCollectionIds(); for (String resultId: collectionIds) { System.out.println(resultId); } } while (listCollectionsResult != null && listCollectionsResult.getNextToken() != null); } }
ListCollections operation request
The input to ListCollections
is the maximum number of collections to
be returned.
{
"MaxResults": 2
}
If the response has more collections than are requested by
MaxResults
, a token is returned that you can use to get the next set of
results, in a subsequent call to ListCollections
. For example:
{
"NextToken": "MGYZLAHX1T5a....",
"MaxResults": 2
}
ListCollections operation
response
Amazon Rekognition returns an array of collections (CollectionIds
). A separate
array (FaceModelVersions
) provides the version of the face model used
to analyze faces in each collection. For example, in the following JSON response,
the collection MyCollection
analyzes faces by using version 2.0 of the
face model. The collection AnotherCollection
uses version 3.0 of the
face model. For more information, see Understanding model versioning.
NextToken
is the token that's used to get the next set of results, in
a subsequent call to ListCollections
.
{
"CollectionIds": [
"MyCollection",
"AnotherCollection"
],
"FaceModelVersions": [
"2.0",
"3.0"
],
"NextToken": "MGYZLAHX1T5a...."
}