AWS AppSync response sorted result?

Viewed 4980

I want to sort $ctx.result.items and reponse the sortedResult
I don't want to manually write Velocity Template Language to sort $ctx.result.items in Response Mapping. Is there any better approach to response the sortedResult in AWS AppSync ?

2 Answers

( if you found a solution I hope this will help someone else )

It depends on how you designed GSI or LSI to your DynamoDB table.

As stated here "DynamoDB builds an unordered hash index on the hash primary key attribute, and a sorted range index on the range primary key attribute."

Here hash index is same as partition key, and range index is same as sort key (old and new terms).

Similar text is stated here - "All items with the same partition key value are stored together, in sorted order by sort key value."

So if you added a GSI or LSI to your DynamoDB table in a way stated above (e.g. all your Products IDs are hash / partition keys and creation times are range / sort keys and you need to sort Products by creation time) you can use something similar to example defined in this page of StackOverflow.

Related