Created
July 17, 2019 20:55
-
-
Save rbk/00f2a946b4a0e5cfd0eb033e9d725069 to your computer and use it in GitHub Desktop.
Return all items from a DynamoDB table by passing the table resource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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