-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathscan_paginate.py
42 lines (32 loc) · 1.06 KB
/
scan_paginate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import print_function # Python 2/3 compatibility
import boto3
from botocore.exceptions import ClientError
# Create Client
session = boto3.session.Session()
dynamoDbClient = session.client('dynamodb')
table_name = 'AmazonBins'
# Track number of Items read
item_count = 0
try:
# Get first 1MB of data
response = dynamoDbClient.scan(
TableName=table_name
)
except ClientError as error:
print("Something went wrong: ")
print(error.response['ResponseMetadata'])
# Track number of Items read
item_count += len(response['Items'])
# Paginate returning up to 1MB of data each iteration
while 'LastEvaluatedKey' in response:
try:
response = dynamoDbClient.scan(
TableName=table_name,
ExclusiveStartKey=response['LastEvaluatedKey']
)
# Track number of Items read
item_count += len(response['Items'])
except ClientError as error:
print("Something went wrong: ")
print(error.response['ResponseMetadata'])
print("Total number of items found: {}".format(item_count))