7

I have setup an API endpoint integration to DynamoDB. I want to query a table using query string parameter as query filter. Unfortunatley I ended up getting error:

Method response body after transformations: {"__type":"com.amazon.coral.service#SerializationException"}

with no clue what is the root cause.

To do the stated above I have taken the following steps:

1) Setup a get method in API gateway

enter image description here

2) In the Method Request I added a parameter to URL Query String Parameters enter image description here

3) In the integration request I added the same parameter from step 2 in URL Query String Parameters enter image description here

4)In DynamoDB table I decalred a new index for the column that I'd like to query

5)In body mapping template:

{
    "TableName": "tjusers",
    "IndexName" "badge-index",
    "KeyConditionExpression": "badge = :v1",
    "ExpressionAttributeValues": {
        ":v1": {
            "S": "$input.params('badge')"
        }
    }
}

enter image description here

THe exception:

xecution log for request f0081606-b521-11e8-adb2-cd8092221b33
Mon Sep 10 17:50:00 UTC 2018 : Starting execution for request: f0081606-b521-11e8-adb2-cd8092221b33
Mon Sep 10 17:50:00 UTC 2018 : HTTP Method: GET, Resource Path: /db/users
Mon Sep 10 17:50:00 UTC 2018 : Method request path: {}
Mon Sep 10 17:50:00 UTC 2018 : Method request query string: {badge=18323}
Mon Sep 10 17:50:00 UTC 2018 : Method request headers: {}
Mon Sep 10 17:50:00 UTC 2018 : Method request body before transformations: 
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request URI: https://dynamodb.us-west-2.amazonaws.com/?Action=Query&badge=11111
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request headers: {Authorization=****************************************************************************************************************************************************************************************************************************************************************************************feb2ac, X-Amz-Date=20180910T175000Z, x-amzn-apigateway-api-id=53zgcztitj, Accept=application/json, User-Agent=AmazonAPIGateway_53zgcztitj, X-Amz-Security-Token=AgoGb3JpZ2l....
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request body after transformations: {
    "TableName": "tjusers",
    "IndexName" "badge-index",
    "KeyConditionExpression": "badge = :v1",
    "ExpressionAttributeValues": {
        ":v1": {
            "S": "11111"
        }
    }
}

Mon Sep 10 17:50:00 UTC 2018 : Sending request to https://dynamodb.us-west-2.amazonaws.com/?Action=Query&badge=18323
Mon Sep 10 17:50:00 UTC 2018 : Received response. Integration latency: 11 ms
Mon Sep 10 17:50:00 UTC 2018 : Endpoint response body before transformations: {"__type":"com.amazon.coral.service#SerializationException"}
Mon Sep 10 17:50:00 UTC 2018 : Endpoint response headers: {Server=Server, Date=Mon, 10 Sep 2018 17:49:59 GMT, Content-Type=application/x-amz-json-1.0, Content-Length=60, Connection=keep-alive, x-amzn-RequestId=ODMJ814D1GBN875T6MTR7BUHGVVV4KQNSO5AEMVJF66Q9ASUAAJG, x-amz-crc32=3948637019}
Mon Sep 10 17:50:00 UTC 2018 : Method response body after transformations: {"__type":"com.amazon.coral.service#SerializationException"}
Mon Sep 10 17:50:00 UTC 2018 : Method response headers: {X-Amzn-Trace-Id=Root=1-5b96aec8-addec09261723342f53a179f, Content-Type=application/json}
Mon Sep 10 17:50:00 UTC 2018 : Successfully completed execution
Mon Sep 10 17:50:00 UTC 2018 : Method completed with status: 200
Nir-Z
  • 819
  • 1
  • 13
  • 31
  • It might be helpful to iterate your troubleshooting to involve [temporarily] not using an Index or URL Query String, in an effort to reduce some variables here. – cellepo Mar 25 '20 at 09:58

2 Answers2

5

You are missing : after "IndexName", that cause SerializationException

enter image description here

zoph
  • 822
  • 1
  • 8
  • 15
  • I had a similar syntax error but couldn't see it in the API Gateway console. I recommend copying your JSON into an editor to make sure it's valid. – nedstark179 Jun 22 '22 at 23:27
0

What is the schema of your tjusers DynamoDB Table? In particular, what is the datatype of badge? If it is Number, for example, you need to be using "N" instead of "S".

(In general, here is a recent new tutorial that meets your requirements and has more details/screenshots than I've seen in others: https://medium.com/@likhita507/using-api-gateway-to-get-data-from-dynamo-db-using-without-using-aws-lambda-e51434a4f5a0)

cellepo
  • 4,001
  • 2
  • 38
  • 57