title: How can I pass binary content to API Gateway from node JS AWS lambda backend using Serverless framework?
body: <p>As we know, API Gateway and lambda support binary request/response, but I have one question for backend programing in node JavaScript.</p>
  
  <p>Environment:</p>
  
  <ul>
  <li>Using Serverless framework, with lambda (not lambda-proxy) integration.</li>
  <li>Response header mapping is:<br>
  Content-Type: integration.response.body.headers.Content-Type</li>
  <li>Response template mappings are:<br>
  image/png: $input.path('$.body')<br>
  image/jpeg: $input.path('$.body')</li>
  <li>Enable Binary Support for image/png and image/jpeg</li>
  </ul>
  
  <p>With above environments, in my code I have response content as Binary (Buffer objects array).<br>
  But, if I give Buffer objects array as response directly, </p>
  
  <pre><code>callback(null,{
      headers: {'Content-Type': 'image/jpeg'},
      body: body
  });
  </code></pre>
  
  <p>Receiving response is like this:</p>
  
  <pre><code>Content-type: image/jpeg
  {type=Buffer, data=[255,216,255,224,0,16,74,70,73,70,0...
  </code></pre>
  
  <p>If I give Buffer objects array as response by base64 encoded, </p>
  
  <pre><code>callback(null,{
      headers: {'Content-Type': 'image/jpeg'},
      body: body.toString('base64')
  });
  </code></pre>
  
  <p>Receiving response is like this:</p>
  
  <pre><code>Content-type: image/jpeg
  /9j/4AAQSkZJRgABAQEASABIAAD/2wBDA...
  </code></pre>
  
  <p>How can I give binary response to API Gateway from node JS backend using Serverless framework?</p>
  
  <p>== PostScript ==</p>
  
  <p>According to this document:<br>
  <a href="https://stackoverflow.com/questions/41037026/aws-api-gateway-binary-output-without-accept-header">AWS API Gateway Binary output without Accept header</a><br>
  We must set "Content Handling" of Integration response change to "CONVERT TO BINARY",  for responding binary response.<br>
  But how can I set this?<br>
  I have no idea both from serverless.yml and AWS console GUI.  </p>
  
  <p>And if I successfully set this Content Handling => CONVERT TO BINARY, might I solve responding binary response?</p>
  
  <p>== Edited Jan. 17th ==</p>
  
  <p>Hi @ka-hou-ieong</p>
  
  <p>You wrote rest-api-id and resource-id, they are in below images, right?</p>
  
  <p><a href="https://i.stack.imgur.com/PzQQe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PzQQe.png" alt="enter image description here"></a></p>
  
  <p>But using these ids, command result said:</p>
  
  <pre><code>$aws apigateway put-integration-response --rest-api-id XXXXXXXX --resource-id XXXXXX --http-method GET --status-code 200 --content-handling CONVERT_TO_BINARY
  
  An error occurred (NotFoundException) when calling the PutIntegrationResponse operation: Invalid Resource identifier specified
  </code></pre>
  
  <p>What wrong with this? I use latest aws-cli (aws-cli/1.11.37 Python/2.7.9 Darwin/16.3.0 botocore/1.5.0)</p>