【发布时间】:2017-04-10 15:12:53
【问题描述】:
正如Complete scan of dynamoDb with boto3 中所述,我构建了一个解决方案,以使用某些条件对 DynamoDB 表进行全扫描。这是我的代码:
def dynamo_scan(table_name, params_dict):
dynamo_table = boto3.resource('dynamodb').Table(table_name)
response = do_scan(dynamo_table, params_dict)
results = response['Items']
while response.get('LastEvaluatedKey'):
print "Iterating"
print response.get('LastEvaluatedKey')
params_dict['ExclusiveStartKey'] = response['LastEvaluatedKey']
response = do_scan(dynamo_table, params_dict)
results.extend(response['Items'])
return results
def do_scan(dynamo_table, params_dict):
return dynamo_table.scan(**params_dict)
但是当代码执行时,它进入了一个无限循环。这是 LastEvaluatedKey 每次迭代的输出:
{u'my_id': u'1698', u'identity': u'2017075002312'}
{u'my_id': u'1883', u'identity': u'85500397082900013318629'}
{u'my_id': u'1698', u'identity': u'2017075002312'}
{u'my_id': u'1883', u'identity': u'85500397082900013318629'}
{u'my_id': u'1698', u'identity': u'2017075002312'}
{u'my_id': u'1883', u'identity': u'85500397082900013318629'}
而且它一直在这两对中循环。
编辑:
我添加了方法 do_scan。
【问题讨论】:
标签: python amazon-web-services amazon-dynamodb boto3 nosql