View a markdown version of this page

標記集合 - Amazon Rekognition

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

標記集合

您可以使用標籤來識別、組織、搜尋和篩選 Amazon Rekognition 集合。每個標籤都是由使用者定義的金鑰和值組成的標籤。

您也能通過 Identity and Access Management (IAM) 使用標籤來管控集合的存取。如需詳細資訊,請參閱使用 AWS 資源標籤控制對資源的存取

將標籤新增至新集合

您可以在使用 CreateCollection 操作建立集合時,將標籤新增至集合。在 Tags 陣列輸入參數中指定一或多個標籤。

AWS CLI

使用您開發人員設定檔的名稱取代 profile_name 的值。

aws rekognition create-collection --collection-id "collection-name" --tags "{"key1":"value1","key2":"value2"}" --profile profile-name

對於 Windows 裝置:

aws rekognition create-collection --collection-id "collection-name" --tags "{\"key1\":\"value1\",\"key2\":\"value2\"}" --profile profile-name
Python

將建立 Rekognition 工作階段的行中 profile_name 值取代為您開發人員設定檔的名稱。

import boto3 def create_collection(collection_id): client = boto3.client('rekognition') # Create a collection print('Creating collection:' + collection_id) response = client.create_collection(CollectionId=collection_id) print('Collection ARN: ' + response['CollectionArn']) print('Status code: ' + str(response['StatusCode'])) print('Done...') def main(): collection_id = 'NewCollectionName' create_collection(collection_id) if __name__ == "__main__": main()

將標籤新增至現有集合

若要將一或多個標籤新增至現有的線索,請使用 TagResource 操作。指定待新增的集合的 Amazon Resource Name (ARN) (ResourceArn) 和標籤 (Tags)。下列範例顯示如何結合標記。

AWS CLI

使用您開發人員設定檔的名稱取代 profile_name 的值。

aws rekognition tag-resource --resource-arn collection-arn --tags "{"key1":"value1","key2":"value2"}" --profile profile-name

對於 Windows 裝置:

aws rekognition tag-resource --resource-arn collection-arn --tags "{\"key1\":\"value1\",\"key2\":\"value2\"}" --profile profile-name
Python

將建立 Rekognition 工作階段的行中 profile_name 值取代為您開發人員設定檔的名稱。

# 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 def create_tag(collection_id): session = boto3.Session(profile_name='default') client = session.client('rekognition') response = client.tag_resource(ResourceArn=collection_id, Tags={ "KeyName": "ValueName" }) print(response) if "'HTTPStatusCode': 200" in str(response): print("Success!!") def main(): collection_arn = "collection-arn" create_tag(collection_arn) if __name__ == "__main__": main()
注意

如果您不知道集合的 Amazon Resource Name,則可以使用該 DescribeCollection 操作。

列出集合中的標籤

若要列出附加至集合的標籤,請使用 ListTagsForResource 操作並指定集合的 ARN (ResourceArn)。回應是連接到指定集合的標籤鍵和值的映射。

AWS CLI

使用您開發人員設定檔的名稱取代 profile_name 的值。

aws rekognition list-tags-for-resource --resource-arn resource-arn --profile profile-name
Python

將建立 Rekognition 工作階段的行中 profile_name 值取代為您開發人員設定檔的名稱。

import boto3 def list_tags(): client = boto3.client('rekognition') response = client.list_tags_for_resource(ResourceArn="arn:aws:rekognition:region-name:5498347593847598:collection/NewCollectionName") print(response) def main(): list_tags() if __name__ == "__main__": main()

輸出會顯示連接至集合的標籤清單:

{ "Tags": { "Dept": "Engineering", "Name": "Ana Silva Carolina", "Role": "Developer" } }

刪除集合中的標籤

若要移除集合中的一個或多個標籤,請使用此 UntagResource 操作。指定要移除的模型 (ResourceArn) 和標籤鍵 (Tag-Keys) 的 ARN。

AWS CLI

使用您開發人員設定檔的名稱取代 profile_name 的值。

aws rekognition untag-resource --resource-arn resource-arn --profile profile-name --tag-keys "key1" "key2"

或者,您可以使用以下格式指定標籤鍵:

--tag-keys key1,key2
Python

將建立 Rekognition 工作階段的行中 profile_name 值取代為您開發人員設定檔的名稱。

import boto3 def list_tags(): client = boto3.client('rekognition') response = client.untag_resource(ResourceArn="arn:aws:rekognition:region-name:5498347593847598:collection/NewCollectionName", TagKeys=['KeyName']) print(response) def main(): list_tags() if __name__ == "__main__": main()