ภาพรวม
สาธิตการลบ tags จากทรัพยากร AWS Glue ต่างๆ เช่น Database, Table, Crawler, Job, Trigger ฯลฯ โดยใช้ untag_resource
รูปแบบ Resource ARN
| ทรัพยากร | รูปแบบ ARN |
|---|---|
| Catalog | arn:aws:glue:region:account-id:catalog |
| Database | arn:aws:glue:region:account-id:database/database-name |
| Table | arn:aws:glue:region:account-id:table/database-name/table-name |
| Connection | arn:aws:glue:region:account-id:connection/connection-name |
| Crawler | arn:aws:glue:region:account-id:crawler/crawler-name |
| Job | arn:aws:glue:region:account-id:job/job-name |
| Trigger | arn:aws:glue:region:account-id:trigger/trigger-name |
| Dev Endpoint | arn:aws:glue:region:account-id:devEndpoint/endpoint-name |
| ML Transform | arn:aws:glue:region:account-id:mlTransform/transform-id |
ตัวอย่างโค้ด
import boto3
from botocore.exceptions import ClientError
def remove_tags(resource_arn, tags_list):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.untag_resource(
ResourceArn=resource_arn,
TagsToRemove=tags_list
)
return response
except ClientError as e:
raise Exception(f"boto3 client error: {e}")
except Exception as e:
raise Exception(f"Unexpected error: {e}")
# ใช้งาน: ลบ tag key "glue-db" จาก database
tags_to_remove = ["glue-db"]
arn = "arn:aws:glue:us-east-1:1122225*****88:database/test-db"
print(remove_tags(arn, tags_to_remove))ผลลัพธ์
{
'ResponseMetadata': {
'RequestId': 'c9f418b0-...',
'HTTPStatusCode': 200,
...
}
}ข้อควรระวัง
tags_listต้องเป็น list ของ key เท่านั้น (ไม่ต้องระบุ value)- ต้องมี permission
glue:UntagResource - ถ้า tag ไม่มีอยู่จริง จะไม่เกิด error