如何使用Boto3从AWS Glue数据目录中获取用户自定义函数的详细信息
让我们看看用户如何从AWS Glue数据目录中获取指定函数定义的详细信息。
示例
获取数据库**employee**中名为**insert_employee_record**的函数定义的详细信息。
问题陈述:使用Python中的**boto3**库从AWS Glue数据目录中获取指定函数定义的详细信息。
解决此问题的步骤/算法
步骤1:导入**boto3**和**botocore**异常以处理异常。
步骤2:**database_name**和**function_name**是必需的参数。它获取给定数据库中给定**function_name**的定义。
步骤3:使用**boto3库**创建AWS会话。确保在默认配置文件中提到了**region_name**。如果未提及,则在创建会话时显式传递**region_name**。
步骤4:为**glue**创建一个AWS客户端。
步骤5:调用**get_user_defined_function**并将**database_name**作为DatabaseName参数,**function_name**作为FunctionName参数传递。
步骤6:它返回给定函数的定义。如果找不到给定函数,则会抛出错误。
步骤7:如果检查函数时出现错误,则处理通用异常。
示例代码
以下代码获取给定函数的定义:
import boto3
from botocore.exceptions import ClientError
def get_function_definition(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("boto3 client error in get_function_definition: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in get_function_definition: " + e.__str__())
a = get_function_definition('employee', 'insert_employee_record')
print(a)输出
{
'UserDefinedFunctions':{
'FunctionName': 'insert_employee_record',
'DatabaseName': 'employee',
'ClassName': 'InsertEmployee',
'OwnerName': 'string',
'OwnerType': 'USER'|'ROLE'|'GROUP',
'CreateTime': datetime(2021,03,15),
'ResourceUris':[
{
'ResourceType': 'JAR'|'FILE'|'ARCHIVE',
'Uri': 'string'
},
],
}
}
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP