Chris Mitchell
Chris Mitchell

Reputation: 903

Insert a Map in DynamoDB

I'm trying to insert map data into a DynamoDB table using API Gateway. Here's my payload:

{
"TableName":"OrderDB",
"Item":{
    "_id": {"S":"04FA887FP2S5R"},
    "_rev": {"S":"9-12e098e2490e1b7c9782597226689403"},
    "_merchantId":{"S":"AXN3EKXT0SJ61"},
    "doc":{"M":{"something":"storedHere"} }
}

And my body mapping template in API Gateway:

{ 
  "TableName": "$input.path('$.TableName')",
  "Item": $input.json('$.Item')
}

Everything works as expected if I remove the doc item from the payload. With trying to post with the map I get the following error:

{
  "__type": "com.amazon.coral.service#SerializationException",
  "Message": "Unexpected value type in payload"
}

All of the examples that I see suggest using the DynamoDB document mapping object, but I don't think this is possible for me because I'm using API Gateway to connect directly to DynamoDB. Is it possible to insert a map this way?

Upvotes: 1

Views: 1887

Answers (1)

Jason Wadsworth
Jason Wadsworth

Reputation: 8885

Your map entry needs the same format as the rest of the items, so instead of "doc":{"M":{"something":"storedHere"} } it should be "doc":{"M":{"something":"S": "storedHere"} }

Upvotes: 1

Related Questions