title: Not able to stream PDF, using AWS gateway/Lambda setup
body: <p><strong>Problem Statement:- Not able to stream PDF, using AWS gateway/Lambda setup.</strong></p>
  
  <p>I've following Setup:-<br><br>
  <strong>Gateway API -> Lambda Function(java) -> S3</strong><br><br>
  Api should stream a PDF back to the client via Lambda from S3 server.
  I am unable to do so.</p>
  
  <p><strong>Things tried</strong><br></p>
  
  <ul>
  
  <li>1) On Lambda side </li>
  
  <br/>
  
    <ul>
  
      <li>Use RequestStreamHandler, write PDF on OutputStream<br/>
              outputStream.write();
  
      <br/>
  
        <ul>
  
          <li>Tried Setting Base64 encoding using following</li>
  
            <ul>
  
              <li>AWS Base64 Utility</li>
  
              <li>java.util Base64 Utility</li>
  
              <li>apache Base64 utility</li>
  
            </ul>
       </ul>
  
       <ul>
  
         <li>Send Byte[] without encoding</li>
  
      </ul>
  
      <br/>
  
      <li>Use non-proxy handler, write PDF as string to one of the output variable.</li>
  
        <ul>
  
          <li>Tried Setting Base64 encoding using following</li>
  
            <ul>
  
              <li>AWS Base64 Utility</li>
  
              <li>java.util Base64 Utility</li>
  
              <li>apache Base64 utility</li>
  
            </ul>
  
        </ul>
  
        <ul>
  
         <li>Send Byte[] without encoding</li>
  
        </ul>
  
   </ul>
  
   <br/>
  
  <li>2) On Gateway Side</li>
  
  <br/>
  
    <ul>
  
      <li>Set Proxy integration</li>
  
      <br/>
  
      <li>Remove Proxy integration</li>
  
      <br/>
  
      <li>Tried Set Content Handling using</li>    
  
        <ul>
  
          <li>Passthrough</li>
  
          <li>Convert to Binary</li>
  
          <li>Convert to String</li>
  
          <li>Set headers</li>
  
            <ul>
  
              <li>Content-Type = 'application/pdf'</li>
  
              <li>Content-Disposition = 'attachment; filename="nameofpdffile.pdf"'</li>
  
            </ul>
  
        </ul>
  
    </ul>
  
  </ul>
  
  <p>I've tried all the permutations/combinations of these 2. However, I am not able to get it to work and documentation around this area seems poor.</p>
  
  <p>When I set Base64 encoding in Lambda and on gateway side specify content handling as convert to binary, i get error, fail to conert using Base64 decode.
  For other combinations, I get binary data as output when I test it using gateway Test funciton, however my client(Postman, Chrome, Safari) fail to convert it to PDF</p>
  
  <p><em>Note:- I've a workaround in place, where I create a signedURL to S3 object, and send it as redirect. However, I am trying to make it work by streaming a binary file using Lambda.</em></p>
  
  <p>Thanks for reading such a long post. Any pointers, links in the right direction are highly appreciated.</p>
  
  <p><strong>- Frustated AWS user :-)</strong></p>