Dùng boto3 gọi stop_workflow_run để dừng một lần chạy workflow cụ thể (cần workflow_name và run_id).
Quy trình
- Import boto3, ClientError.
- Hàm nhận
workflow_namevàrun_id. - Tạo session, client Glue.
- Gọi
glue_client.stop_workflow_run(Name=..., RunId=...). - Trả về response metadata.
- Xử lý ngoại lệ.
Code mẫu
import boto3
from botocore.exceptions import ClientError
def dung_workflow(workflow_name, run_id):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.stop_workflow_run(Name=workflow_name, RunId=run_id)
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(dung_workflow("test-daily", "wr_64e88024..."))
Kết quả
{'RunId': 'wr_64e88024...', 'ResponseMetadata': {'RequestId': '782e953b-...', 'HTTPStatusCode': 200, ...}}