

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 删除用户
<a name="delete-user"></a>

您可以使用该[DeleteUser](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteUser.html)操作根据提供的用户 ID 从集合中删除用户。请注意，在删除指定的用户 ID 之前，与该用户 ID 关联的所有人脸都将与用户 ID 断开关联。

**删除用户 (SDK)**

1. 如果您尚未执行以下操作，请：

   1. 使用 `AmazonRekognitionFullAccess` 权限创建或更新 IAM 用户。有关更多信息，请参阅 [步骤 1：设置 AWS 账户并创建用户](setting-up.md#setting-up-iam)。

   1. 安装和配置 AWS CLI 和 AWS SDK。有关更多信息，请参阅 [第 2 步：设置 AWS CLI and AWS 软件开发工具包](setup-awscli-sdk.md)。

1. 使用以下示例调用 `DeleteUser` 操作。

------
#### [ Java ]

   此 Java 代码示例删除了一名用户。

   ```
   import com.amazonaws.services.rekognition.AmazonRekognition;
   import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
   import com.amazonaws.services.rekognition.model.DeleteUserRequest;
   import com.amazonaws.services.rekognition.model.DeleteUserResult;
   
   
   public class DeleteUser {
   
       public static void main(String[] args) throws Exception {
   
   
           AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
   
           //Replace collectionId and userId with the name of the user that you want to delete from that target collection.
   
           String collectionId = "MyCollection";
           String userId = "demoUser";
           System.out.println("Deleting existing user: " +
                   userId);
   
           DeleteUserRequest request = new DeleteUserRequest()
                   .withCollectionId(collectionId)
                   .withUserId(userId);
   
           rekognitionClient.deleteUser(request);
       }
   
   }
   ```

------
#### [ AWS CLI ]

   此 AWS CLI 命令使用 `create-user` CLI 操作删除用户。

   ```
   aws rekognition delete-user --collection-id MyCollection 
   --user-id {{user-id}} --collection-id {{collection-name}} --region {{region-name}}
   ```

------
#### [ Python ]

   此 Python 代码示例删除了一名用户。

   ```
   # 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.)
   
   import boto3
   from botocore.exceptions import ClientError
   import logging
   
   logger = logging.getLogger(__name__)
   session = boto3.Session(profile_name='profile-name')
   client = session.client('rekognition')
   
   def delete_user(collection_id, user_id):
           """
           Delete the user from the given collection
   
           :param collection_id: The ID of the collection where user is stored.
           :param user_id: The ID of the user in the collection to delete.
           """
           logger.info(f'Deleting user: {collection_id}, {user_id}')
           try:
               client.delete_user(
                   CollectionId=collection_id,
                   UserId=user_id
               )
           except ClientError:
               logger.exception(f'Failed to delete user with given user id: {user_id}')
               raise
   
   def main():
       collection_id = "collection-id"
       user_id = "user-id"
       delete_user(collection_id, user_id)
   
   if __name__ == "__main__":
       main()
   ```

------