在boto3中分页DynamoDB查询

Jon*_*han 6 python pagination boto3 aws-lambda

如果它们跨越多个页面,我如何遍历DynamoDB查询中的所有结果?这个答案意味着分页内置于查询函数中(至少在v2中),但是当我在v3中尝试这个时,我的项目似乎有限:

import boto3
from boto3.dynamodb.conditions import Key, Attr

dynamodb = boto3.resource('dynamodb')
fooTable = dynamodb.Table('Foo')
response = fooTable.query(
    KeyConditionExpression=Key('list_id').eq('123')
)

count = 0

for i in response['Items']:
    count += 1

print count # Prints a subset of my total items
Run Code Online (Sandbox Code Playgroud)

omu*_*thu 2

ExclusiveStartKey 是您正在查找的属性的名称。使用上一操作中为 LastEvaluatedKey 返回的值。

ExclusiveStartKey 的数据类型必须是 String、Number 或 Binary。不允许设置数据类型。

http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html#DynamoDB.Client.query

  • 可能应该更清楚 - 我知道我可以使用“ExclusiveStartKey”手动分页。但在链接的答案中,@garnaat(boto 的作者!)建议它应该在查询函数中开箱即用。 (2认同)