Skip to content

Instantly share code, notes, and snippets.

@rbk
Created July 17, 2019 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbk/00f2a946b4a0e5cfd0eb033e9d725069 to your computer and use it in GitHub Desktop.
Save rbk/00f2a946b4a0e5cfd0eb033e9d725069 to your computer and use it in GitHub Desktop.
Return all items from a DynamoDB table by passing the table resource.
def scan_all(dynamodb_table):
"""Return all items from a DynamoDB table by passing the table resource."""
results = []
has_items = True
last_key = False
while has_items:
if last_key:
data = dynamodb_table.scan(ExclusiveStartKey=last_key)
else:
data = dynamodb_table.scan()
if 'LastEvaluatedKey' in data:
has_items = True
last_key = data['LastEvaluatedKey']
else:
has_items = False
last_key = False
for item in data['Items']:
results.append(item)
return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment