skip to Main Content

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 .

2

Answers


  1. 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 the ExclusiveStartKey on the next scan.

    On the first scan operation (page == 0) you would simply pass Limit=10 in the query parameters.

    On the second scan operation (page == 1) you would pass Limit=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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search