次のタグオペレーションを使用して、リソースのタグを追加、削除、または一覧表示します。
API | CLI | アクションの説明 |
---|---|---|
TagResource |
tag-resource |
指定した ARN を持つリソースの 1 つ以上のタグを追加または上書きします。 |
UntagResource |
untag-resource |
指定した ARN を持つリソースから 1 つ以上のタグを削除します。 |
ListTagsForResource |
list‑tags‑for‑resource |
指定した ARN を持つリソースの 1 つ以上のタグを一覧表示します。 |
リソースを作成する際にタグを追加する
ワークグループまたはデータカタログの作成時にタグを追加するには、tags
パラメータを CreateWorkGroup
または CreateDataCatalog
API オペレーション、あるいは AWS CLI の create-work-group
または create-data-catalog
コマンドで使用します。
API アクションを使用してタグを管理する
次の例は、タグ API アクションを使用して、ワークグループおよびデータカタログのタグを管理する方法を示しています。例は、Java プログラミング言語で記述されています。
次の例では、ワークグループ workgroupA
に 2 つのタグを追加します。
List<Tag> tags = new ArrayList<>();
tags.add(new Tag().withKey("tagKey1"
).withValue("tagValue1"
));
tags.add(new Tag().withKey("tagKey2"
).withValue("tagValue2"
));
TagResourceRequest request = new TagResourceRequest()
.withResourceARN("arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
)
.withTags(tags);
client.tagResource(request);
次の例では、データカタログ datacatalogA
に 2 つのタグを追加します。
List<Tag> tags = new ArrayList<>();
tags.add(new Tag().withKey("tagKey1
").withValue("tagValue1
"));
tags.add(new Tag().withKey("tagKey2
").withValue("tagValue2
"));
TagResourceRequest request = new TagResourceRequest()
.withResourceARN("arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA
")
.withTags(tags);
client.tagResource(request);
注記
同じリソースに重複したタグキーを追加しないでください。そのようにした場合には、Athena はエラーメッセージを発行します。別の TagResource
アクションで既存のタグキーを使用してリソースにタグを付けると、新しいタグ値によって古い値が上書きされます。
次の例では、ワークグループ tagKey2
から workgroupA
を削除します。
List<String> tagKeys = new ArrayList<>();
tagKeys.add("tagKey2
");
UntagResourceRequest request = new UntagResourceRequest()
.withResourceARN("arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
)
.withTagKeys(tagKeys);
client.untagResource(request);
次の例では、データカタログ tagKey2
から datacatalogA
を削除します。
List<String> tagKeys = new ArrayList<>();
tagKeys.add("tagKey2
");
UntagResourceRequest request = new UntagResourceRequest()
.withResourceARN("arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA
")
.withTagKeys(tagKeys);
client.untagResource(request);
次の例では、ワークグループ workgroupA
のタグを一覧表示します。
ListTagsForResourceRequest request = new ListTagsForResourceRequest()
.withResourceARN("arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
);
ListTagsForResourceResult result = client.listTagsForResource(request);
List<Tag> resultTags = result.getTags();
次の例では、データカタログ datacatalogA
のタグを一覧表示します。
ListTagsForResourceRequest request = new ListTagsForResourceRequest()
.withResourceARN("arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA
");
ListTagsForResourceResult result = client.listTagsForResource(request);
List<Tag> resultTags = result.getTags();
AWS CLI を使用してタグを管理する
次の例では、AWS CLI を使用してデータカタログのタグを作成および管理する方法を示します。
tag-resource
コマンドは、指定されたリソースに 1 つ以上のタグを追加します。
構文
aws athena tag-resource --resource-arn
arn:aws:athena:
region
:account_id
:datacatalog/catalog_name
--tags
Key=string
,Value=string
Key=string
,Value=string
--resource-arn
パラメータは、タグを追加するリソースを指定します。--tags
パラメータは、リソースにタグとして追加するスペース区切りのキーと値のペアのリストを指定します。
例
次の例では、mydatacatalog
データカタログにタグを追加します。
aws athena tag-resource --resource-arn arn:aws:athena:us-east-1:111122223333:datacatalog/mydatacatalog --tags Key=Color,Value=Orange Key=Time,Value=Now
結果を表示するには、list-tags-for-resource
コマンドを使用します。
create-data-catalog
コマンドを使用する際にタグを追加する方法については、「カタログの登録: Create-data-catalog」(カタログを登録する: Create-data-catalog) を参照してください。
list-tags-for-resource
コマンドは、指定されたリソースのタグを一覧表示します。
構文
aws athena list-tags-for-resource --resource-arn
arn:aws:athena:
region
:account_id
:datacatalog/catalog_name
--resource-arn
パラメータは、タグを一覧表示するリソースを指定します。
次の例では、mydatacatalog
データカタログのタグを一覧表示します。
aws athena list-tags-for-resource --resource-arn arn:aws:athena:us-east-1:111122223333:datacatalog/mydatacatalog
次のサンプル結果は JSON 形式です。
{
"Tags": [
{
"Key": "Time",
"Value": "Now"
},
{
"Key": "Color",
"Value": "Orange"
}
]
}
untag-resource
コマンドは、指定されたタグキーとその関連値を、指定されたリソースから削除します。
構文
aws athena untag-resource --resource-arn
arn:aws:athena:
region
:account_id
:datacatalog/catalog_name
--tag-keys key_name
[key_name
...]
--resource-arn
パラメータは、タグを削除するリソースを指定します。--tag-keys
パラメータは、キー名のスペース区切りリストを取ります。untag-resource
コマンドは、指定されたキー名ごとに、キーとその値の両方を削除します。
次の例では、Color
カタログリソースから Time
および mydatacatalog
キーとそれぞれの値を削除します。
aws athena untag-resource --resource-arn arn:aws:athena:us-east-1:111122223333:datacatalog/mydatacatalog --tag-keys Color Time