刪除使用者 - Amazon Rekognition

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

刪除使用者

可以使用 DeleteUser 操作,以根據提供的 UserID 從集合中刪除使用者。請注意,在刪除指定的 UserID 之前,與 UserID 相關聯的任何人臉都會與 UserID 斷開關聯。

刪除使用者 (SDK)
  1. 如果您尚未執行:

    1. 建立或更新具有 AmazonRekognitionFullAccess 權限的 IAM 使用者賬戶。如需詳細資訊,請參閱步驟 1:設定 AWS 帳戶並建立使用者

    2. 安裝和設定 AWS CLI 和 AWS SDKs。如需詳細資訊,請參閱步驟 2:設定 AWS CLI 和 AWS SDKs

  2. 使用下列範例來呼叫 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 命令會使用 CLI create-user 操作刪除使用者。

    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()