0

AWS 模型架构

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "QuestionsModel",
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
        "placeholder" : { "type":"string" },
        "type" : { "type":"string" },
        "order": { "type": "integer" },
        "prompt": { "type": "string" },
        "section_name": { "type": "string" }
        }
    }
}

AWS 集成响应 - 映射模板 - application/json

使用 Velocity 模板语言映射一个数组...

#set($inputRoot = $input.path('$'))
[
#foreach($elem in $inputRoot)
{
  "type" : "$elem.type",
  "placeholder" : "$elem.placeholder",
  "order" : "$elem.order",
  "prompt" : "$elem.prompt",
  "section_name" : "$elem.section_name"
} 
#if($foreach.hasNext),#end
#end
]

AWS Lambda 函数

def lambda_handler(event, context):
    client = boto3.client('dynamodb')

    response = client.scan(
        TableName='Question',
        AttributesToGet=[
            'type',
            'order',
            'section_name',
            'prompt',
            'placeholder'])

    return = response['Items']

iOS 应用模型

iOS 模型有一个typeNSString 类型的字段,其中填充了值{S=Hello World}

我宁愿iOS字段等于Hello World省我解析{S=*}

我哪里错了?

4

2 回答 2

0

我在另一个问题中确定了答案。

未记录,但您可以在映射模板中的字段名称后简单地指定类型:

#set($inputRoot = $input.path('$'))
[
#foreach($elem in $inputRoot)
{
  "field1" : "$elem.field1.S",
  "field2" : $elem.field2.N
}#if($foreach.hasNext),#end
#end
]

请注意,字符串字段需要用引号分隔,而数字则不需要。

于 2016-03-02T10:59:07.200 回答
0

您是否在方法响应中设置了响应模型?这是 API Gateway 提供的基本演练。http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-models.html

于 2016-03-01T18:21:08.533 回答