Boto3 Athena没有显示所有表格

时间:2017-12-21 23:08:04

标签: python boto3 amazon-athena paginator aws-glue

尝试使用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'] 

1 个答案:

答案 0 :(得分:1)

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

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

应该是:

`paginator = client.get_paginator('get_tables')`.

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

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

请参阅此功能here的文档。

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

for page_index, page in enumerate(page_iterator):