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

Lấy chi tiết Trigger trong AWS Glue Data Catalog với Boto3

Dùng boto3 gọi get_trigger để lấy metadata đầy đủ của một trigger (tên, loại, trạng thái, lịch trình, mô tả...).

Quy trình

  1. Import boto3, ClientError.
  2. Hàm nhận trigger_name.
  3. Tạo session, client Glue.
  4. Gọi glue_client.get_trigger(Name=...).
  5. Trả về response.
  6. Xử lý ngoại lệ.

Code mẫu

import boto3
from botocore.exceptions import ClientError

def lay_chi_tiet_trigger(trigger_name):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.get_trigger(Name=trigger_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_chi_tiet_trigger('01_PythonShellTest1'))

Kết quả

{'Trigger': {'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'}}