我得到
"__type": "com.amazon.coral.service#SerializationException"
作为邮差的回复&在API网关的测试控制台
尝试使用API代理服务直接向dynamodb发布记录。我引用了这篇AWS文章- https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/
这是我的映射
{
"TableName": "TableNameGoesHere",
"Item": {
"id" : "$context.requestId"
"eventName" : "$input.path('$.eventName')",
"timestamp" : $input.path('$.timestamp'),
"answers": "$util.parseJson($input.path('$.answers'))"
}
}
更新:我按要求做了。它工作了,但现在如果我尝试添加一个JSON对象数组,它会给我上面相同的错误-这就是我现在要做的。请帮忙-在谷歌上也找不到任何东西
#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
]" }
}
}
解决将对象数组作为有效负载的一部分的挑战。
For Request Payload
{
"emailId": "v@a.com",
"responses": [
{
"question": "q1",
"answer": "a1"
},
{
"question": "q2",
"answer": "a2"
}
]
}
模板为
#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
]
}
}
}
集成响应模板(结构与请求类似)
#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
]
}
您的映射模板不匹配DynamoDB格式。应该是这样的,
{
"TableName": "Comments",
"Item": {
"commentId": {
"S": "$context.requestId"
},
"pageId": {
"S": "$input.path('$.pageId')"
},
"userName": {
"S": "$input.path('$.userName')"
},
"message": {
"S": "$input.path('$.message')"
}
}
}