Abd*_*ala 4 amazon-web-services aws-api-gateway
我正进入(状态
"__type": "com.amazon.coral.service#SerializationException"
Run Code Online (Sandbox Code Playgroud)
作为邮递员和 API Gateway 测试控制台中的回复
尝试使用 API 代理服务将记录直接发布到 dynamodb。我指的是这篇 AWS 文章 - https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for -动态数据库/
这是我的映射
{
"TableName": "TableNameGoesHere",
"Item": {
"id" : "$context.requestId"
"eventName" : "$input.path('$.eventName')",
"timestamp" : $input.path('$.timestamp'),
"answers": "$util.parseJson($input.path('$.answers'))"
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我按照要求做了......并且它起作用了,但是现在如果我尝试添加一个 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
]" }
}
}
Run Code Online (Sandbox Code Playgroud)
解决将对象数组作为有效负载一部分的挑战。
对于请求有效负载
{
"emailId": "v@a.com",
"responses": [
{
"question": "q1",
"answer": "a1"
},
{
"question": "q2",
"answer": "a2"
}
]
}
Run Code Online (Sandbox Code Playgroud)
模板将是
#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
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
集成响应模板(与请求类似的结构)
#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
]
}
Run Code Online (Sandbox Code Playgroud)
您的映射模板与 DynamoDB 格式不匹配。它应该是这样的,
{
"TableName": "Comments",
"Item": {
"commentId": {
"S": "$context.requestId"
},
"pageId": {
"S": "$input.path('$.pageId')"
},
"userName": {
"S": "$input.path('$.userName')"
},
"message": {
"S": "$input.path('$.message')"
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14553 次 |
| 最近记录: |