DynamoDB扫描中的无限循环

时间:2017-04-10 15:12:54

标签: python amazon-web-services amazon-dynamodb boto3 nosql

正如this site中所解释的,我构建了一个使用某种条件完全扫描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。

1 个答案:

答案 0 :(得分:0)

我不确定你的points = [a; b; c; d]; plot3(points(:,1), points(:,2), points(:,3), 'o'); 到底做了什么,但这样做有效:

do_scan()