Skip to content

Mapping Template & Proxy Integration

vishaldesai edited this page Dec 11, 2017 · 1 revision

Examples of mapping templates:

  1. Change the key name based on value

#set($inputRoot = $input.path('$')) { "count": $inputRoot.count, "items": [ #foreach($elem in $inputRoot.items) { "author": { #if ("$elem.author.last_name" == 'Doe') {"lastname": "$elem.author.last_name"} #else {"last": "$elem.author.last_name"} #end , "email": "$elem.author.email", "first_name": "$elem.author.first_name" } }#if($foreach.hasNext),#end

#end ], "version": $inputRoot.version }

  1. Assign key name from JSON payload to PartitionKey.

#set ($bodyObj = $util.parseJson($input.body))

{ "StreamName": "cox-poc-test-stream", "Data": "$util.base64Encode($input.json('$.body'))", "PartitionKey": "$bodyObj.contact.name" }

Example of Proxy Integration:

For proxy integration, lambda function must return output in specific format.

exports.handler = (event, context, callback) => { var responseBody = { "requestId": context.awsRequestId, "logGroupName": context.logGroupName };

var response = {
    "statusCode": 200,
    "headers": {
        "my_header": "my_value"
    },
    "body": JSON.stringify(responseBody),
    "isBase64Encoded": false
};
callback(null, response);

};

Clone this wiki locally