1

尝试使用 BOTO3 python 获取 Athena Table 中的表名列表。

这是我的代码;我认为我尝试做分页器是不正确的。任何帮助表示赞赏

import boto3

client = boto3.client('glue')
responseGetDatabases = client.get_databases()
databaseList = responseGetDatabases['DatabaseList']

for databaseDict in databaseList:
    databaseName = databaseDict['Name']
    if "dbName_" in databaseName:
        print '\ndatabaseName: ' + databaseName
        responseGetTables = client.get_tables( DatabaseName = databaseName )
        paginator = client.get_paginator(['TableList'])
        for page in paginator:
            tableList = responseGetTables['TableList']
            for tables in tableList:
                print tables['Name'] 
4

1 回答 1

2

get_paginator 函数参数必须是操作的名称。看起来您正在尝试对该get_tables功能进行分页,所以

    paginator = client.get_paginator(['TableList'])

应该:

    paginator = client.get_paginator('get_tables')

获得分页器对象后,您需要调用paginator.paginate以检索迭代器。您可以像这样发送数据库参数:

    page_iterator = paginator.paginate(
        DatabaseName=databaseDict['Name'],
        PaginationConfig={
            'MaxItems': 123,
            'PageSize': 123,
            'StartingToken': 'string'
        }
    )

在此处查看此功能的文档。

现在您有了迭代器,您可以通过枚举来调用 for 循环:

for page_index, page in enumerate(page_iterator):
于 2018-01-26T22:07:47.813 回答