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
- Import boto3, ClientError.
- Hàm nhận
trigger_name. - Tạo session, client Glue.
- Gọi
glue_client.start_trigger(Name=...). - Trả về response metadata.
- 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, ...}}