aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -
i getting
"__type": "com.amazon.coral.service#serializationexception"
as reply in postman & in test console in api gateway
trying post record directly dynamodb using api proxy services.. referring aws article - https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/
here's mapping
{ "tablename": "tablenamegoeshere", "item": { "id" : "$context.requestid" "eventname" : "$input.path('$.eventname')", "timestamp" : $input.path('$.timestamp'), "answers": "$util.parsejson($input.path('$.answers'))" } }
update: did asked ... , worked if try add array of json objects gives me above same error - here's trying now. please - couldnt find on google well
#set($inputroot = $input.path('$')) { "tablename": "answer", "item": { "id": { "s": "$context.requestid" }, "eventname": { "s": "$input.path('$.eventname')" }, "timestamp" : { "n": "$input.path('$.timestamp')" }, "answers": { "s": "$input.path('$.answers')" }, "line": { "s" : "[ #foreach($elem in $inputroot.line) { "questionid" : "$elem.questionid", "answer" : "$elem.answer" }#if($foreach.hasnext),#end #end ]" } } }
to address challenge of having array of objects part of payload.
for request payload
{ "emailid": "v@a.com", "responses": [ { "question": "q1", "answer": "a1" }, { "question": "q2", "answer": "a2" } ] }
template be
#set($inputroot = $input.path('$')) { "tablename": "customers", "item": { "leadid": { "s": "$context.requestid" }, "emailid": { "s": "$input.path('$.emailid')" }, "responses": { "l": [ // list type #foreach($elem in $inputroot.responses) // loop thru array { "m": { // map type "answer": { "s": "$elem.answer" }, "question": { "s": "$elem.question" } } } #if($foreach.hasnext),#end #end ] } } }
integration response template (similar structure request)
#set($inputroot = $input.path('$')) { "$results": [ #foreach($elem in $inputroot.items) { "emailid": "$elem.emailid.s", "responses": [ #foreach($resp in $elem.responses.l) { "question": "$resp.m.question.s", "answer": "$resp.m.answer.s" } #if($foreach.hasnext),#end #end ] } #if($foreach.hasnext),#end #end ] }
Comments
Post a Comment