根据此文档,我使用AWS API网关作为DynamoDb的代理: https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/
在API网关中进行测试时,结果如下:
{
"Count": 6,
"Items": [
{
"mini_description": {
"S": "A veg sandwich"
},
"item_description": {
"S": "A veg sandwich filled with a lot of healthy vegetables"
},
"id": {
"S": "6d0e0870-......-c5ccfbc0424c"
},
"image_url": {
"S": "https://......png"
},
"price": {
"N": "25"
},
"name": {
"S": "Veg Sandwich"
},
"item_type": {
"S": "Main Dish"
}
},
{
"mini_description": {
"S": "A normal hot coffee"
},.....
我需要以下格式:
{
"Count": 6,
"Items": [
{
"mini_description": "A veg sandwich",
"item_description": "A veg sandwich filled with a lot of healthy vegetables",
"id": "6d0e0870-.......-c5ccfbc0424c",
"image_url": "https://.......png",
"price": 25,
"name": "Veg Sandwich",
"item_type": "Main Dish"
},
{
"mini_description": "A normal hot coffee",............
是否有通过API网关的集成响应来更改此设置的程序?
答案 0 :(得分:0)
如果您有直接通往DynamoDB的API网关,则无法解组数据。但是,您可以在API网关和DynamoDB之间添加Lambda函数,然后使用the unmarshall function from Javascript SDK(或任何其他首选语言)删除DynamoDB JSON元素。
答案 1 :(得分:0)
我通过在API网关中GET方法的集成响应中使用以下映射模板来实现此目标:
#set($inputRoot = $input.path('$'))
{
"Items": [
#foreach($elem in $inputRoot.Items)
{
"mini_description" : "$elem.mini_description.S",
"item_description" : "$elem.item_description.S",
"id" : "$elem.id.S",
"image_url" : "$elem.image_url.S",
"price" : $elem.price.N,
"name" : "$elem.name.S",
"item_type" : "$elem.item_type.S"
}#if($foreach.hasNext),#end
#end
]
}