Introduce AWS API Gateway Data Mapping Template

Weijing Jay Lin
1 min readMar 3, 2020

--

By default AWS API Gateway will print out headers in root path, the sample code would be something like this:

{
"statusCode": 200,
"body": "{\"message\":\"Welcome!\"}",
"headers": {
"x-powered-by": "Express",
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"content-length": "22",
"date": "Tue, 03 Mar 2020 05:53:59 GMT",
"connection": "close"
},
"isBase64Encoded": false
}

But we actually just need body part instead of everything. Using {proxy+} could be a solution for the resource in the subdirectory eg “/videos”, but it won’t root directory “/”.

AWS API Gateway Data Mapping

AWS provide API Gateway Data Mapping template for setupping customized response content. It could be used for the solution to address this problem.

So in order to display the body of the above response, we could use following content in the Mapping Templates settings.

template settings in Integration Response

Mapping Template does more than just displaying the body, it could be more powerful that help you to build the desired data model map.

Please check references below for more information regarding AWS Data Mapping Template:

--

--