0
votes

my app needs to query a list of objects from dynamoDB and I do so using an api written in python (boto3) I want the user to be able to view the items by pages and request the next/ previous one

how can i implement in It I the api? my table is struct with 2 keys,

'key1': user1 //string
'key2' : item1 //string

'key1': user1
'key2' : item2 

'key1': user1
'key2' : item3

'key1': user1
'key2' : item4

I'm currently using query to get all the items for a user but on large scale I would like to get it by pages. scan operation has a parameter called "LastEvaluatedKey" so I thought about using that parameter to set the ExclusiveStartKey and limit the result to the number of items per page but it still scans the entire table right?

1
boto3 offers paginators, which implement what you want. There is also one for query: boto3.amazonaws.com/v1/documentation/api/latest/reference/…Dunedan

1 Answers

0
votes

DynamoDB will return a LastEvaluatedKey whenever the results of a query or scan operation is greater than 1MB.

A scan is still an inefficient operation, even if you are paginating the results. If you want to provide pagination in your application, you'll get the best performance by paginating over the results of a query operation. Avoid scan if you can!