Dùng boto3 gọi get_triggers với tham số DependentJobName để lấy các trigger có thể kích hoạt job đó. Nếu không truyền job_name, trả về tất cả trigger.
Quy trình
- Import boto3, ClientError.
- Hàm nhận
job_name(tùy chọn). - Tạo session, client Glue.
- Gọi
glue_client.get_triggers(DependentJobName=job_name). - Trả về danh sách trigger.
- Xử lý ngoại lệ.
Code mẫu
import boto3
from botocore.exceptions import ClientError
def lay_trigger_cua_job(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("Lỗi boto3 client: " + str(e))
except Exception as e:
raise Exception("Lỗi không mong đợi: " + str(e))
print(lay_trigger_cua_job('employee_details'))
Kết quả
{'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'}]}