title: AWS Lambda and AWS API Gateway: How to send a binary file?
body: <p>I have a lambda function which fetches a file from s3 using the input key in event and needs to send the same to client. I am using the following function to get the file from s3</p>
  
  <pre><code>function getObject(key){
    var params = {
      Bucket: "my_bucket",
      Key: key   
    }
    return new Promise(function (resolve, reject){
      s3.getObject(params, function (err, data){
        if(err){
          reject(err);
        }
        resolve(data.Body)
      })
    })
  }
  </code></pre>
  
  <p>If I send the response of this promise (buffer) to <code>context.succeed</code>, it is displayed as a JSON array on front end. How can I send it as a file ? The files can be either ZIP or HTTP Archive (HAR) files. The s3 keys contain the appropriate extension. I am guessing it has got something to do with the "Integration Response" in API Gateway. But not able to figure out where to change</p>