Khi người dùng muốn xóa một workflow từ AWS Data Catalog.
Ví dụ − Xóa workflow 'test' từ tài khoản của bạn.
Đề bài − Sử dụng thư viện boto3 trong Python để xóa một workflow có sẵn trong tài khoản.
Cách tiếp cận/Thuật toán giải quyết
Bước 1 − Nhập boto3 và botocore exceptions để xử lý ngoại lệ.
Bước 2 − Truyền tham số workflow_name cần xóa từ AWS Glue Catalog.
Bước 3 − Tạo phiên AWS bằng boto3. Đảm bảo region_name trong profile mặc định. Nếu không, truyền rõ ràng region_name khi tạo phiên.
Bước 4 − Tạo client AWS cho glue.
Bước 5 − Gọi delete_workflow và truyền workflow_name làm tham số Name.
Bước 6 − Nó sẽ xóa workflow và trả về response metadata. Lưu ý, nếu workflow không tìm thấy trong AWS Data Catalog, nó không ném ngoại lệ.
Bước 7 − Xử lý ngoại lệ chung nếu có lỗi xảy ra khi kiểm tra job.
Ví dụ
Sử dụng code sau để xóa workflow liệt kê trong tài khoản người dùng:
import boto3
from botocore.exceptions import ClientError
def delete_a_workflow(workflow_name):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.delete_workflow(Name=workflow_name)
return response
except ClientError as e:
raise Exception("boto3 client error in delete_a_workflow: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in delete_a_workflow: " + e.__str__())
print(delete_a_workflow("test"))
Kết quả
{'Name': 'test', 'ResponseMetadata': {'RequestId': '............-59a9bc817e0f', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 21 Feb 2021 05:37:11 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '35', 'connection': 'keep-alive', 'x-amzn-requestid': '............-59a9bc817e0f'}, 'RetryAttempts': 0}}