Complete scan of dynamoDb with boto3

前端 未结 8 1924
有刺的猬
有刺的猬 2020-11-29 04:08

My table is around 220mb with 250k records within it. I\'m trying to pull all of this data into python. I realize this needs to be a chunked batch process and looped throug

8条回答
  •  有刺的猬
    2020-11-29 04:52

    I think the Amazon DynamoDB documentation regarding table scanning answers your question.

    In short, you'll need to check for LastEvaluatedKey in the response. Here is an example using your code:

    import boto3
    dynamodb = boto3.resource('dynamodb',
                              aws_session_token=aws_session_token,
                              aws_access_key_id=aws_access_key_id,
                              aws_secret_access_key=aws_secret_access_key,
                              region_name=region
    )
    
    table = dynamodb.Table('widgetsTableName')
    
    response = table.scan()
    data = response['Items']
    
    while 'LastEvaluatedKey' in response:
        response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
        data.extend(response['Items'])
    

提交回复
热议问题