title: AWS Java Lambda Function with API Gateway - POJO input and OutputStream output
body: <p>I'm creating a simple AWS Lambda Function in Java that creates and returns a PDF. The function is invoked by an API Gateway. The input is a simple POJO class, but the output should be an <code>OutputStream</code> for the file.</p>
  
  <p>For the input, I've tried creating a POJO class and just using the <code>APIGatewayProxyRequestEvent</code> and either works fine. Below is a simple example I used that takes in a input and prints back the query string parameters. </p>
  
  <pre><code>public class LambdaFunctionHandler implements RequestHandler&lt;APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent&gt; {
  
      @Override
      public APIGatewayProxyResponseEvent handleRequest( APIGatewayProxyRequestEvent input, Context context ) {
  
          return new APIGatewayProxyResponseEvent()
              .withStatusCode(200)
              .withHeaders(Collections.emptyMap())
              .withBody("{\"input\":\"" + input.getQueryStringParameters() + "\"}");
      }
  
  }
  </code></pre>
  
  <p>That works fine, but now I need to alter it to use an <code>OutputStream</code> as the the output. How can this be done? I see that I can use the <code>RequestStreamHandler</code> and AWS has some <a href="https://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-stream.html" rel="nofollow noreferrer">documentation</a> on implementing this. However, that would force my input to be an InputStream, which I'm not sure how that would work with the API Gateway. </p>
  
  <p>How can I serve this PDF back to the client requesting it?</p>