【发布时间】:2017-03-23 02:36:36
【问题描述】:
我一直在尝试获取我的 GSI 之一上的所有记录,并且发现只有在我进行扫描时,才有一个选项可以在响应中使用 LastEvaluatedKey 进行循环。我没有找到更好的方法来使用pagination 在boto3 中使用查询。是否可以使用查询进行分页。
导入 boto3 from boto3.dynamodb.conditions import Key, Attr
dynamodb = boto3.resource('dynamodb')
res = table.query(
TableName='myTable',
IndexName='my-index',
KeyConditionExpression=Key('myVal').eq(1)
)
while 'LastEvaluatedKey' in res:
for item in res['Items']:
print item #returns only a subset of them
【问题讨论】:
-
请提供更多关于您想要实现的目标的详细信息。
-
我正在尝试查询索引以获取 dynamodb 表中的所有记录。上面的代码 sn-p 只返回了 100 条记录,而有数百万条记录。无法使用查询功能进行分页。我可以使用扫描进行分页。
标签: amazon-dynamodb boto3