title: How to inject a header from the errormessage
body: <p>I've been attempting to inject a custom header for a error response status (and failing).</p>
  
  <p>I have a very simple lambda being used</p>
  
  <pre><code>exports.handler = (event, context, callback) =&gt; {
     // TODO implement
  
     //callback(null, 'Hello from Lambda');
  
     var error = {
         name:"error", 
         message:"I am a failure",
         statusCode: 400
     };
  
     error["x-test"] = 'foo';
  
     callback(JSON.stringify(error), null);
  };
  </code></pre>
  
  <p>In the api gateway, I've done the following:</p>
  
  <p>set up CORS to include x-test
  responsetemplate = <code>"$input.path('$.errorMessage')"</code>
  responseparameter to include: </p>
  
  <pre><code>method.response.header.x-test = integration.response.body.x-test
  </code></pre>
  
  <p>Also, I have a statusCode mapped using <code>'.*statusCode.*?400.*'</code></p>
  
  <p>This has turned out empty.</p>
  
  <p>so I decided to take a step back and see what happens if I do:</p>
  
  <pre><code>method.response.header.x-test = integration.response.body
  </code></pre>
  
  <p>I found that I get the stringified response of errorMessage.</p>
  
  <pre><code>{"x-test":"{\"errorMessage\":\"{\\\"name\\\":\\\"error\\\",\\\"message\\\":\\\"I am a failure\\\",\\\"statusCode\\\":400,\\\"x-test\\\":\\\"foo\\\"}\"}"}
  </code></pre>
  
  <p>So I decided to change the responsetemplate to force it to json by doing the following:</p>
  
  <p>responsetemplate = <code>"$util.parseJson($input.path('$.errorMessage'))"</code></p>
  
  <p>and I still get the stringified response:</p>
  
  <pre><code>{"x-test":"{\"errorMessage\":\"{\\\"name\\\":\\\"error\\\",\\\"message\\\":\\\"I am a failure\\\",\\\"statusCode\\\":400,\\\"x-test\\\":\\\"foo\\\"}\"}"}
  </code></pre>
  
  <p>My guess is that it doesn't transform as expected, but only for the final output.</p>
  
  <p>So how would you take a value and shove it into a header?</p>
  
  <p>Thanks,
  Kelly</p>