2
votes

just like the question asked here

I do a query or scan operation on dynamoDB using dynamoDB proxy service on AWS API Gateway to read data for the Client and I get DynamoDB formatted JSON data in reply.

Although I can use the "Method Response" to convert but when the Data is above 1000 records - I cannot handle it due to the limitation of foreach loop in Method Response.

Is there a flag or a setting somewhere in dynamodb or in api gateway such that I get normal json rather than the dynamoDB formatted JSON ?

DynamoDB Formatted JSON example

{
  "videos": [
    {
      "file": {
        "S": "file1.mp4"
      },
      "id": {
        "S": "1"
      },
      "canvas": {
        "S": "This is Canvas1"
      }
    },
    {
      "file": {
        "S": "main.mp4"
      },
      "id": {
        "S": "0"
      },
      "canvas": {
        "S": "this is a canvas"
      }
    }
  ]
}

Normal Json example of the same

{
  "videos": [
    {
      "file": "file1.mp4",
      "id": "1",
      "canvas": "This is Canvas1"
    },
    {
      "file": main.mp4",
      "id": "0",
      "canvas": "this is a canvas"
    }
  ]
}
2

2 Answers

2
votes

Using an Integration Response mapper!

The mapper would probably look something like: (I'm using your provided response)

#set($inputRoot = $input.path('$'))
{
  "videos": [
#foreach($elem in $inputRoot.Items)
  { "file": "$elem.file.S",
    "id": "$elem.id.S",
    "canvas": "$elem.canvas.S" }#if($foreach.hasNext), #end
#end 
  ] 
}

Please consult the linked documentation for more complete guidance on attaching AWS Services directly to API Gateway.

1
votes

The possible solution for this is using a aws lambda to query/scan dynamoDb and reply back the domain object after converting it into a json using some json lib, like GSON or jackson.

If any one has knowledge about an alternate option - please do post here. Thanks