0

AWS Model schema

{
"$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 Integration Response - Mapping Template - application/json

Mapping using Velocity Template Language An array...

#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 function

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 app the Model

The iOS Model has a field type of type NSString populated with the value {S=Hello World}

I'd rather the iOS field be equal to Hello World saving me parsing {S=*}

Where am I going wrong?

Carl
  • 2,896
  • 2
  • 32
  • 50

2 Answers2

0

Did you set up the response model in the method response? Here is the basic walkthrough provided by API Gateway. http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-models.html

Ka Hou Ieong
  • 5,835
  • 3
  • 20
  • 21
  • Yes. I've followed that page and built an iOS API. I note the model I've defined. I'll investigate if I'm returning the array from lambda/dynamodb correctly. – Carl Mar 01 '16 at 19:57
0

I pinned down the answer in another question.

Undocumented but you can simply specify the type after the field name in a mapping template:

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

Note that string fields need to be delimited in quotes and numbers don't.

Community
  • 1
  • 1
Carl
  • 2,896
  • 2
  • 32
  • 50