Paginating a DynamoDB query in boto3

ⅰ亾dé卋堺 提交于 2019-12-23 09:42:34

问题


How can I loop through all results in a DynamoDB query, if they span more than one page? This answer implies that pagination is built into the query function (at least in v2), but when I try this in v3, my items seem limited:

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

回答1:


ExclusiveStartKey is the name of the attribute which you are looking for. Use the value that was returned for LastEvaluatedKey in the previous operation.

The data type for ExclusiveStartKey must be String, Number or Binary. No set data types are allowed.

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



来源:https://stackoverflow.com/questions/39355377/paginating-a-dynamodb-query-in-boto3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!