title: AWS API Gateway Header and Body Mappings in Integration Response
body: <p>I am trying to properly setup Body Mapping and Header Mapping in the Integration Response for an API Gateway endpoint.</p>
  
  <p>In our Lambda we have </p>
  
  <pre><code>if (response.statusCode == 200) {
      context.succeed(output);
  } else if (response.statusCode == 206) {
      var paginationObject = {
          errorType : "PartialContent",
          errorCode : 206,
          detailedMessage : "PartialContent Returned",
          stackTrace : [],
          data : {
                 output
          }
      };
  
      context.fail(JSON.stringify(paginationObject));
  }
  </code></pre>
  
  <p>I then handle fetching this in the Integration Response using a Lambda Error Regex of <strong>.*PartialContent.*</strong> and have my Body Mapping Template as</p>
  
  <pre><code>#set($allParams = $input.params())
  #set($body = $util.parseJson($input.json('$.errorMessage')))
  
  $body
  </code></pre>
  
  <p>This gives me the correct HTTP status code and JSON output, but it has too much data in the body. The response looks like:</p>
  
  <pre><code>{
    "errorType":"PartialContent",
    "errorCode":206,
    "detailedMessage":"PartialContent Returned",
    "stackTrace":[],
    "data":{
      "output":{
        "status":206,
        "bodyJson":[{"call_date":"2017-08-19 18:17:21"}],
        "headers":{"date":"Thu, 02 Nov 2017 18:36:52 GMT",
                   "server":"Apache",
                   "x-pagination-page-size":10}
      }
    }
  }
  </code></pre>
  
  <p>I want the headers to actually appear as headers in the response, and I want the body to just be the content inside of bodyJson</p>
  
  <p>I've tried to change the body mapping template to use <strong>$body.data.output.bodyJson</strong>, but when I do that the body is completely empty. I've also got the headers set in the Header Mappers, trying both <strong>integration.response.body.headers.x-pagination-page-size</strong> and <strong>integration.response.header.x-pagination-page-size</strong> but both times the header is blank, even though I can see the proper values in the JSON output.</p>
  
  <p>How do I get just the bodyJson element to be output as the body of the response? And how do I properly get the headers mapped?</p>