ใช้ Boto3 ดึง Triggers ที่เกี่ยวข้องกับ Job เฉพาะใน AWS Glue Data Catalog
ตัวอย่าง
ดึง Triggers ที่เชื่อมโยงกับ Job ชื่อ employee_details
ขั้นตอน/อัลกอริทึม
- Import boto3 และ botocore.exceptions.ClientError
- job_name เป็นพารามิเตอร์ทางเลือก (ถ้าไม่ระบุ จะดึง Triggers ทั้งหมด)
- สร้าง AWS Session และ Glue Client
- เรียก get_triggers(DependentJobName=job_name)
- คืนค่ารายการ Triggers
- จัดการ Exception
ตัวอย่างโค้ด
import boto3
from botocore.exceptions import ClientError
def get_details_of_triggers(job_name=None):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_triggers(DependentJobName=job_name)
return response
except ClientError as e:
raise Exception("boto3 client error in get_details_of_triggers: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in get_details_of_triggers: " + e.__str__())
a = get_details_of_triggers('employee_details')
print(a)
ผลลัพธ์
{'Triggers': [{'Name': '01_PythonShellTest1', 'WorkflowName': 'arn:aws:iam::1234:role/dev-edl', 'Id': 'string', 'Type': 'SCHEDULED'|'CONDITIONAL'|'ON_DEMAND', 'State': 'CREATING'|'CREATED'|'ACTIVATING'|'ACTIVATED'|'DEACTIVATING'|'DEACTIVATED'|'DELETING'|'UPDATING', 'Description': 'string', 'Schedule': 'string'}]}