0

I am using AWS Lambda to get result from Dynamo DB. The returned result from Lambda is this:

Response:
{
  "Items": [
    {
      "name": "unknown",
      "rid": "1589816220971",
      "rtime": "2020-05-18 23:37:12",
      "status": "unsuccessful"
    },
    {
      "name": "acap",
      "rid": "1589816876343",
      "rtime": "2020-05-18 23:48:10",
      "status": "successful"
    },
  ],
  "Count": 2,
  "ScannedCount": 2
}

But i wanted the returned result inverted as this because i want the recent result first.

Response:
{
  "Items": [
    {
      "name": "acap",
      "rid": "1589816876343",
      "rtime": "2020-05-18 23:48:10",
      "status": "successful"
    },
    {
      "name": "unknown",
      "rid": "1589816220971",
      "rtime": "2020-05-18 23:37:12",
      "status": "unsuccessful"
    },
  ],
  "Count": 2,
  "ScannedCount": 2
}

Is there any way of doing that or more better way to return the latest item first from DynamoDB using Lambda?

jarmod
  • 71,565
  • 16
  • 115
  • 122
  • 1
    Is it a Nodejs lambda, python... ? – BTL May 18 '20 at 17:05
  • 1
    Does this answer your question? [Is it possible to ORDER results with query or scan in DynamoDB?](https://stackoverflow.com/questions/9297326/is-it-possible-to-order-results-with-query-or-scan-in-dynamodb) – dege May 18 '20 at 17:17
  • This looks like results from `scan`. You'll have to sort the results locally. – jarmod May 18 '20 at 17:35
  • You might look at [https://stackoverflow.com/questions/26250095/how-can-i-scan-an-index-in-reverse-in-dynamodb](https://stackoverflow.com/questions/26250095/how-can-i-scan-an-index-in-reverse-in-dynamodb) – iOSonntag May 18 '20 at 18:04
  • Yes I am using scan @jarmod, can you elaborate on how to sort locally? And i have tried dege solution but it returns error. – Muhamad Asyraf Othman May 19 '20 at 04:00
  • Every programming language has a native sort feature. You didn’t indicate a programming language, however. Search for sorting a list with your programming language. – jarmod May 19 '20 at 12:59

0 Answers0