aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.03k stars 568 forks source link

Mention that collections must contain letters #6316

Closed marcelchelo closed 4 weeks ago

marcelchelo commented 1 month ago

Describe the issue

Mention that to avoid InvalidParameterException the parameters must contain characters. For example a character or string of an integer. ie. "1" Returns error InvalidParameterException. But if you have ie. "user-1". It works well and InvalidParameterException is not returned.

Even if you a collection with collectionId: "1" exists.

Screenshot 2024-07-26 at 11 24 04 AM Screenshot 2024-07-26 at 11 24 35 AM

Links

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/rekognition/command/DeleteUserCommand/

marcelchelo commented 1 month ago

when a collection is named "something-{id}" No errors are thrown and the api can easily find the collection, if it exists.
if a collection is called "{id}" where id is a number, the api throws an error InvalidParameterException. Even though the collection exists.

all input requirements being equal: const input = { "ClientRequestToken": "550e8400-e29b-41d4-a716-446655440001", "CollectionId": "MyCollection", "UserId": "DemoUser" };

zshzbh commented 1 month ago

Hey @marcelchelo ,

I can't reproduce this error. Steps to reproduce:

  1. Add new collection - "CollectionId": "1",

  2. Add new users to the collection - "UserId": "user_1", "UserId": "1", "UserId": "2"

  3. List all existing users -

    Screenshot 2024-07-26 at 3 00 55 PM
  4. Create a file index.js and add the code to delete UserId: "1" -

    
    import { RekognitionClient, DeleteUserCommand} from "@aws-sdk/client-rekognition"; 

const client = new RekognitionClient({region: "us-west-2",}); const input = { // DeleteUserRequest CollectionId: "1", UserId: "1", }; const command = new DeleteUserCommand(input); const response = await client.send(command); console.log(response);


5.  Run `node index.js` .
6. And then got a 200 response 
<img width="396" alt="Screenshot 2024-07-26 at 3 03 10 PM" src="https://github.com/user-attachments/assets/d2d95e6c-efe4-451e-8497-96f2ae267060">

This is the output to list all users in this collection - 
<img width="408" alt="Screenshot 2024-07-26 at 3 03 15 PM" src="https://github.com/user-attachments/assets/541e93b3-352e-4566-8bca-5218eadd6f1e">

_______________________________________________________________
But, if I run `node index.js ` one more time and got the same error as you posted - 

/Users/zshzbh/Desktop/newProj/node_modules/@aws-sdk/client-rekognition/dist-cjs/index.js:2725 const exception = new InvalidParameterException({ ^

InvalidParameterException: Request has invalid parameters at de_InvalidParameterExceptionRes (/Users/zshzbh/Desktop/newProj/node_modules/@aws-sdk/client-rekognition/dist-cjs/index.js:2725:21) at de_CommandError (/Users/zshzbh/Desktop/newProj/node_modules/@aws-sdk/client-rekognition/dist-cjs/index.js:2577:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /Users/zshzbh/Desktop/newProj/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20 at async /Users/zshzbh/Desktop/newProj/node_modules/@smithy/core/dist-cjs/index.js:165:18 at async /Users/zshzbh/Desktop/newProj/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38 at async /Users/zshzbh/Desktop/newProj/node_modules/@aws-sdk/client-rekognition/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:34:22 at async file:///Users/zshzbh/Desktop/newProj/6313/index.js:37:18 { '$fault': 'client', '$metadata': { httpStatusCode: 400, requestId: 'b0df5202-ee68-4ff9-8de2-91f01fb8fd2b', extendedRequestId: undefined, cfId: undefined, attempts: 1, totalRetryDelay: 0 }, Code: 'InvalidParameterException', Logref: undefined, __type: 'InvalidParameterException' }

Node.js v20.15.1


I can see this error because I have deleted userId "1" but wanted to delete userId "1" again. However, deleting a non-existing user is not something we want to do with this command. 

It seems that you passed an invalid CollectionId or UserId to the command. 

I'd like to recommend to add a user existence check before user deletion. 

You list list all users in certain collection using this part of code  - 
```js
const input_l = {
    "CollectionId": "1"
  };
  const command_l = new ListUsersCommand(input_l);
  const response_l = await client.send(command_l);
console.log(response_l);

Please let us know if you have any questions!

Thanks! Maggie

github-actions[bot] commented 1 month ago

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] commented 2 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.