Its not possible to obtain order over all keys in a DynamoDB table. The only possible approach would be to
Scan the entire table and implement your sorting on the client side.
You could of course use DynamoDB Streams and keep pointers to the top 10 liked posts, if that is something your application intends to show. Then you could simply call
BatchGetItems with the 10 listed items.
Another option would be to create a GSI with a single attribute as the PK, for example
POSTS and the number of likes as the SK.
Then you could simply
Query your GSI with the key
POSTS and use
Be warned that this is not a scalable solution as your GSI key is a single value. This will limit your tables writes to approximately 1000WCU per second. That's a decision you can make depending on your throughput needs.
AWS scan and query not working as intendedasked 5 months ago
DynamoDB: query nested items from a mapasked 6 months ago
Limitations of dynamoDB & GraphQLasked 24 days ago
DynamoDB Query Request Limit Not working?asked 2 years ago
GraphQL pagination returning same results from dynamoDB
How to query data from dynamoDB table with multiple filter layers?Accepted Answer
How do I set up an AWS Amplify project to query an existing AWS AppSync API?asked 6 months ago
Implementing Pagination with RDS Resolver Mapping Templateasked 24 days ago
pagination question on appsync to elasticsearchAccepted Answerasked 3 years ago
sortkey in DynamoDB query with pagination limitAccepted Answerasked 25 days ago