如何使用 Boto3 获取 AWS 账户中所有 Schema 的列表
本文将介绍用户如何获取 AWS 账户中所有 Schema 的列表。
示例
获取 AWS Glue 数据目录中所有可用的 Schema 列表。
问题陈述:使用 Python 中的 boto3 库获取所有 Schema 的列表。
解决此问题的方法/算法
步骤 1:导入 boto3 和 botocore 异常以处理异常。
步骤 2:此函数没有参数。
步骤 3:使用 boto3 库创建 AWS 会话。确保在默认配置文件中提到了 region_name。如果未提及,则在创建会话时显式传递 region_name。
步骤 4:为 glue 创建 AWS 客户端。
步骤 5:现在使用 list_schemas 函数
步骤 6:它返回 AWS Glue 数据目录中所有 Schema 的列表,其中包含 Schema 的有限详细信息。它不包含状态为“Deleting”的 Schema。它只包含可用 Schema 的列表。如果没有 Schema,则返回一个空字典。
步骤 7:如果在检查 Schema 时出现错误,则处理通用异常。
代码示例
以下代码获取所有 Schema 的列表:-
import boto3
from botocore.exceptions import ClientError
def list_of_schemas()
session = boto3.session.Session()
glue_client = session.client('glue')
try:
schemas_name = glue_client.list_schemas()
return schemas_name
except ClientError as e:
raise Exception("boto3 client error in list_of_schemas: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in list_of_schemas: " + e.__str__())
print(list_of_schemas())输出
{
'Schemas':[
{
'RegistryName': 'employee_details',
'SchemaName': 'employee_table',
'SchemaArn': 'string',
'Description': 'Schema for employees record',
'Status': 'AVAILABLE',
'CreatedTime': 'string',
'UpdatedTime': 'string'
},
{
'RegistryName': 'security_details',
'SchemaName': 'security_table',
'SchemaArn': 'string',
'Description': 'Schema for security record',
'Status': 'AVAILABLE',
'CreatedTime': 'string',
'UpdatedTime': 'string'
},
],
'Request': ……
}
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP