Reputation: 2093
I am wondering how could I paginate in AWS Dynamodb database in the most efficient way possible. I have found a few solutions playing with the ExclusiveStartKey
like this:
var params = {
"TableName" : "abcd",
"ExpressionAttributeNames" : {"#someexperssion":"someexperssion"},
"ExpressionAttributeValues" : {":someexperssion" : "value"},
"Limit" : 20,
"ExclusiveStartKey" : {"id": "9ee10f6e-ce6d-4820-9fcd-cabb0d93e8da"}
};
The problem I found with these solutions is that You always have to know the last key ExclusiveStartKey
. When I only want to retrieve the 4th page with a 10 items, do I have to query all the items before the 4th page to know what is the last key?
I would like to access the db only once when trying to get the nth page. Is that possible?
Thank You all!
Upvotes: 2
Views: 324
Reputation: 10185
Well, you could implement your own custom pagination using a global secondary index for your application's read mechanism. Having a GSI dedicated for reading paged data will eliminate the need to read prior pages in DynamoDB's native implementation.
The downside of this is that you have to implement a reliable paging system and it might offer challenges in terms of grouping which batch should be grouped together, if its not much a pain for your team to work on and time for development is not an issue, might be what you are looking for.
Upvotes: 0