翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
タグコレクション
タグを使用して、Amazon Rekognition コレクションを識別、整理、検索、フィルタリングできます。各タグは、ユーザー定義のキーと値で構成されるラベルです。
Identity and Access Management (IAM) を使用して、タグ でコレクションへのアクセスを制御することもできます。詳細については、AWS 「リソースタグを使用したリソースへのアクセスの制御」を参照してください。
新しいコレクションにタグを追加する
CreateCollection オペレーション を使用して、コレクションの作成時にタグを追加できます。Tags 配列入力パラメーターで、 1 つ以上のタグを指定します。
- 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()
既存のコレクションにタグを追加する
既存の証跡に 1 つ以上のタグを追加するには、TagResource オペレーションを使用します。コレクションの Amazon リソースネーム (ARN) (ResourceArn) と、追加したいタグ (Tags) を指定します。次の例は、2 つのタグを追加する方法を示しています。
- 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 リソース名がわからない場合は、DescribeCollection オペレーションを使用することができます。
コレクションに添付されるタグを一覧表示するには、ListTagsForResource オペレーションを実行し、コレクション (ResourceArn) の ARN を指定します。。応答は、指定されたコレクションに添付されるタグのキーと値のマップです。
- 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"
}
}
コレクションからタグを削除する
コレクションから 1 つ以上のタグを削除するには、UntagResource オペレーションを使用する。モデル (ResourceArn) の ARN と 削除したいタグキー (Tag-Keys) を指定します。
- 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()