Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent responses from CreateCollectionCommand and DescribeCollectionCommand #6704

Open
3 of 4 tasks
jeffayers31 opened this issue Nov 30, 2024 · 3 comments
Open
3 of 4 tasks
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@jeffayers31
Copy link

jeffayers31 commented Nov 30, 2024

Checkboxes for prior research

Describe the bug

I'm using AWS SDK v3, and specifically, "@aws-sdk/client-rekognition": "^3.699.0". I'm trying out AWS Rekognition, and during my testing I'm getting inconsistent responses from CreateCollectionCommand and DescribeCollectionCommand functions from AWS SDK v3. CreateCollectionCommand response returns a CollectionArn (Arn is capitalized) field while DescribeCollectionCommand returns CollectionARN (Arn is all caps) field, and their values are slightly different. CreateCollectionCommand returns a value in CollectionArn that starts with 'arn:' at the beginning while DescribeCollectionCommand returns a value in CollectionARN without the 'arn:'.

I'm using Vitest testing framework for my Typescript, and when I run both commands and compare the results, I get an error:
expect(createResponse.CollectionARN).toBe(getResponse.CollectionARN);
But, even if I change it to:
expect(createResponse.CollectionArn).toBe(getResponse.CollectionARN);
It still fails because the values are inconsistent.
Expected: "arn:aws:rekognition:us-east-1:************:collection/rm-test-collection"
Received: "aws:rekognition:us-east-1:************collection/rm-test-collection"

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/client-rekognition@3.699.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.12.2

Reproduction Steps

// Two wrappers: one for creating collection and another for getting a collection. The createCollection    
// calls getCollection to confirm the collection doesn't exist. If it does, createCollection returns the 
// getCollection response.
async createCollection(collectionId: string): Promise<any> {
        const params = { CollectionId: collectionId };

        try {
            const response = await this.getCollection(collectionId);
            if (response === null) {
                const collectionResponse = await this.rekognitionClient.send(new CreateCollectionCommand(params));
                this.logger.info('createCollection: Collection created:', JSON.stringify(collectionResponse, null, 2));
                return collectionResponse;
            }
            else {
                this.logger.info('createCollection: Collection already exists:', JSON.stringify(response, null, 2));
                return response;
            }
        } catch (error) {
            this.logger.error('createCollection: Error creating collection:', error as Error);
            throw error;
        }
    }

    async getCollection(collectionId: string): Promise<any> {
        const params = { CollectionId: collectionId };

        try {
            const data = await this.rekognitionClient.send(new DescribeCollectionCommand(params));
            this.logger.info('getCollection: Collection details:', JSON.stringify(data, null, 2));
            return data;
        } catch (error) {
            this.logger.error('getCollection: Error getting collection:', error as Error);
        }

        return null;
    }
// Test run in a Vitest unit test. Note RekognitionService is the class wrapper that contains
// the two methods listed above.
        it('4. createCollection response should equal getCollection response', async () => {
            const collectionId = 'rm-test-collection';
            const rekognitionService = new RekognitionService(region, logger);
            const createResponse = await rekognitionService.createCollection(collectionId);
            expect(createResponse).toBeDefined();
            const getResponse = await rekognitionService.getCollection(collectionId);
            expect(getResponse).toBeDefined();
            expect(createResponse.CollectionArn).toBe(getResponse.CollectionARN);
        });

Observed Behavior

FAIL source/tests/unit/Rekognition-real.test.ts > RekognitionService Real Images > man.jpg is not in a collection testing > 4. createCollection response should equal getCollection response
AssertionError: expected 'aws:rekognition:us-east-1:*…' to be 'arn:aws:rekognition:us-east-1:…' // Object.is equality

Expected: "arn:aws:rekognition:us-east-1::collection/rm-test-collection"
Received: "aws:rekognition:us-east-1:
:collection/rm-test-collection"

❯ source/tests/unit/Rekognition-real.test.ts:51:50
49| const getResponse = await rekognitionService.getCollection(collec…
50| expect(getResponse).toBeDefined();
51| expect(createResponse.CollectionArn).toBe(getResponse.CollectionA…
| ^
52| });

Expected Behavior

I would expect that there is consistency in the field names and field values. Either return 'CollectionArn' or 'CollectionARN' from both calls and make sure the values returned are identical.

Possible Solution

I'm not sure if AWS enforces consistency between libraries, but within the same library, calls should be consistent. Please make them consistent.

Additional Information/Context

No response

@jeffayers31 jeffayers31 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2024
@zshzbh zshzbh self-assigned this Dec 5, 2024
@zshzbh zshzbh added p2 This is a standard priority issue investigating Issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 5, 2024
@zshzbh
Copy link
Contributor

zshzbh commented Dec 5, 2024

Hey @jeffayers31

Thanks for the feedback!

I can reproduce this issue.
The code I have -

import { RekognitionClient, CreateCollectionCommand, DescribeCollectionCommand } from "@aws-sdk/client-rekognition";
import { fromIni } from '@aws-sdk/credential-providers';

// Configure the Rekognition client
const rekognitionClient = new RekognitionClient({
    region: "us-east-1", // Replace with your region
    credentials: fromIni({ profile: 'default' }) // Use your AWS profile
});

// Collection name to be created and described
const collectionName = "my-face-collection";

// Function to create a collection
async function createCollection(collectionId) {
    try {
        console.log(`Creating collection: ${collectionId}`);
        
        const command = new CreateCollectionCommand({
            CollectionId: collectionId
        });
        
        const response = await rekognitionClient.send(command);
        
        console.log("Collection created successfully:");
        console.log("Collection ARN:", response.CollectionArn);
 
        return response;
    } catch (error) {
        console.error("Error creating collection:", error);
        throw error;
    }
}

// Function to describe a collection
async function describeCollection(collectionId) {
    try {
        console.log(`Describing collection: ${collectionId}`);
        
        const command = new DescribeCollectionCommand({
            CollectionId: collectionId
        });
        
        const response = await rekognitionClient.send(command);
        
        console.log("Collection details:");
        console.log("Collection ARN:", response.CollectionArn);
        
        return response;
    } catch (error) {
        console.error("Error describing collection:", error);
        throw error;
    }
}

// Main function to demonstrate usage
async function main() {
    try {
        // Create the collection
        console.log("Step 1: Creating Collection");
        await createCollection(collectionName);
        // returns aws:rekognition:us-east-1:XXX:collection/my-face-collection
        // Wait for a moment to ensure the collection is created
        console.log("\nWaiting for collection to be fully created...");
        await new Promise(resolve => setTimeout(resolve, 2000));
        
        // Describe the collection
        console.log("\nStep 2: Describing Collection");
        const res = await describeCollection(collectionName);
        console.log("res: ", res);
        //returns - arn:aws:rekognition:us-east-1:XXX:collection/my-face-collection
    } catch (error) {
        console.error("Main function error:", error);
    }
}

// Execute the main function
main();

In CreateCollectionCommand's response, the returned arn is aws:rekognition:us-east-1:XXX:collection/my-face-collection, but in the DescribeCollectionCommand's response, the arn is arn:aws:rekognition:us-east-1:XXX:collection/my-face-collection. One Arn starts with "arn" but another on doesn't

@zshzbh
Copy link
Contributor

zshzbh commented Dec 5, 2024

It seems that the service team generates two sets of arn -

CreateCollection response

DescribeCollection response

I will cut a ticket to the service team.

Thanks!

@zshzbh
Copy link
Contributor

zshzbh commented Dec 5, 2024

internal ref - V1601989251

@zshzbh zshzbh added service-api This issue is due to a problem in a service API, not the SDK implementation. and removed investigating Issue is being investigated and/or work is in progress to resolve the issue. labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants