Skip to content

Commit df50169

Browse files
authored
Merge pull request aws-samples#86 from 12Manoz/master
Python Example: Pagination of data returned by partiql execute statement.
2 parents df29170 + a49d465 commit df50169

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import boto3
2+
3+
from botocore.exceptions import ClientError
4+
5+
# execute statment works with low level client.
6+
dynamodb = boto3.client('dynamodb', region_name='us-east-1')
7+
params = {
8+
'statement': 'SELECT * FROM "cerberus-test-3"',
9+
'next_token': None
10+
}
11+
12+
# Shows we cannot use inbuilt pagination for execute statement.
13+
print(dynamodb.can_paginate('execute_statement'))
14+
15+
while True:
16+
try:
17+
if params['next_token'] is None:
18+
response = dynamodb.execute_statement(
19+
Statement=params['statement'])
20+
21+
elif params['next_token']:
22+
response = dynamodb.execute_statement(
23+
Statement=params['statement'], NextToken=params['next_token'])
24+
25+
# for paginated results response includes nexttoken which can be used for pagination
26+
if 'NextToken' in response:
27+
params['next_token'] = response['NextToken']
28+
print("Next token is updated")
29+
else:
30+
print("paginated statement executed succesfully")
31+
break
32+
except ClientError as error:
33+
print(error)

0 commit comments

Comments
 (0)