【发布时间】:2021-02-28 00:39:47
【问题描述】:
我在 python 中使用 boto3,但我相信问题和逻辑应该在所有语言中通用。
我知道table.scan() 理论上应该返回所有记录,但实际上它们的 scan() 结果大小限制为 1MB。建议基于 LastEvaluatedKey 创建一个 while 循环,但这也不会给我所有的结果(15200 而不是 16000),代码在这里:
dynamodb = boto3.resource('dynamodb', region_name='eu-west-2')
table = dynamodb.Table(dBTable)
response = table.scan()
print("item_count:", table.item_count)
print("response1:", response["Count"])
items=[]
while 'LastEvaluatedKey' in response and response['LastEvaluatedKey'] != "":
print("response:", response["Count"])
items+=response["Items"]
response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
如何可靠地获取所有记录?
【问题讨论】:
标签: amazon-web-services aws-lambda amazon-dynamodb boto3 dynamodb-queries