Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Lấy danh sách Trigger liên kết với Job trong AWS Glue với Boto3

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

  1. Import boto3, ClientError.
  2. Hàm nhận job_name (tùy chọn).
  3. Tạo session, client Glue.
  4. Gọi glue_client.get_triggers(DependentJobName=job_name).
  5. Trả về danh sách trigger.
  6. 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'}]}