I am trying to implement pagination + sorting of records in my rest API using dynamodb.
There are 4 attributes in the table:-
- a - pk ( partition key)
- b - SK (range key)
- createdAt - normal attribute
- updatedAt - normal attribute
Since dynamodb always sorts data by default on the range key. This will be a problem when I would like to sort based on created or updated with pagination as some data will be on page 1 for 2020 and 2021 years and some data on page 2 will be of 2022 and 2020 if the range key item starts with z ( just an example)
is there any workaround for this where we can sort dynamic data with pagination and other attributes that are not range key? Also i dont want to use index for the attributes as it can ensure cost