如何使用 Boto3 获取 AWS 账户中存在的架构列表
在本文中,我们将了解用户如何获取AWS账户中存在的所有架构的列表。
示例
获取AWSGlue数据目录中所有可用架构的列表。
问题陈述:使用Python中的boto3库获取所有模式的列表。
解决这个问题的方法/算法
第一步:导入boto3和botocore异常处理异常。
步骤2:此函数中没有参数。
步骤3:使用boto3lib创建AWS会话。确保在默认配置文件中提到region_name。如果未提及,则在创建会话时显式传递region_name。
第4步:为glue创建一个AWS客户端。
第5步:现在使用list_schemas函数
步骤6:它返回AWSGlue数据目录中存在的所有架构的列表,其中包含有限的架构详细信息。它不包括状态为正在删除的模式。它只有可用模式的列表。如果没有模式,则它返回一个空的字典。
第7步:如果在检查模式时出现问题,则处理通用异常。
示例代码
以下代码获取所有模式的列表-
import boto3
frombotocore.exceptionsimport 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': ……
}热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下