在boto3中分页DynamoDB查询 [英] Paginating a DynamoDB query in boto3

查看:410
本文介绍了在boto3中分页DynamoDB查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果DynamoDB查询中的所有结果跨越一页以上,该如何遍历所有结果? 此答案表示分页已内置在查询函数中(至少在v2中),但是当我在v3中尝试时,我的物品似乎有限:

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

推荐答案

ExclusiveStartKey是要查找的属性的名称. 使用在上一个操作中为LastEvaluatedKey返回的值.

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

ExclusiveStartKey的数据类型必须为String,Number或Binary.不允许设置数据类型.

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

这篇关于在boto3中分页DynamoDB查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆