I want someone to help me with how to implement pagination in boto3 without query, NextToken. I want the dynamoDB data to be sent to the frontend but 10 entries at a time and every time send the next 10 entries to the frontend.
First I thought I could use the query but the primary key would filter most of the data and I want all the results, just 10 entries at a time.
Also on the frontend, it has to be like page1(10 entries), page2(next 10 ) , like that .
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
2
Answers
To implement pagination with a DynamoDB scan operation you have to save the
LastEvaluatedKey
value that was returned from the first scan, and pass that as theExclusiveStartKey
on the next scan.On the first scan operation (
page == 0
) you would simply passLimit=10
in the query parameters.On the second scan operation (
page == 1
) you would passLimit=10, ExclusiveStartKey=<lastScanResult.LastEvaluatedKey>
.Note that you will have to pass the
LastEvaluatedKey
value to the frontend as part of your result data, the frontend will have to store that in memory, and send it as part of the request data when it requests the next page.There’s no direct approach from what I’m getting your question.
Above mentioned approach by Mark B is good but not for your case you won’t be able to move to any page other than next or go to previous page directly with this approach.
You can implement a not so cost efficient approach by adding a field to db of page number and using a lambda function to maintain pagination in db