Dùng boto3 gọi get_user_defined_function để lấy chi tiết một hàm cụ thể (cần database_name và function_name).
Quy trình
- Import boto3, ClientError.
- Hàm nhận
database_namevàfunction_name. - Tạo session, client Glue.
- Gọi
glue_client.get_user_defined_function(DatabaseName=..., FunctionName=...). - Trả về metadata hàm.
- Xử lý ngoại lệ.
Code mẫu
import boto3
from botocore.exceptions import ClientError
def lay_dinh_nghia_ham(database_name, function_name):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_user_defined_function(DatabaseName=database_name, FunctionName=function_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_dinh_nghia_ham('employee', 'insert_employee_record'))
Kết quả
{'UserDefinedFunction': {'FunctionName': 'insert_employee_record', 'DatabaseName': 'employee', 'ClassName': 'InsertEmployee', 'OwnerName': 'string', 'OwnerType': 'USER|ROLE|GROUP', 'CreateTime': datetime(2021,3,15), 'ResourceUris': [{'ResourceType': 'JAR|FILE|ARCHIVE', 'Uri': 'string'}]}}