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

Khởi chạy Trigger trong AWS Glue Data Catalog với Boto3

Dùng boto3 gọi start_trigger để kích hoạt trigger ngay lập tức, bất kể lịch trình.

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.start_trigger(Name=...).
  5. Trả về response metadata.
  6. Xử lý ngoại lệ.

Code mẫu

import boto3
from botocore.exceptions import ClientError

def khoi_chay_trigger(trigger_name):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.start_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(khoi_chay_trigger("test-daily"))

Kết quả

{'Name': 'test-daily', 'ResponseMetadata': {'RequestId': 'b2109689-...', 'HTTPStatusCode': 200, ...}}