title: AWS API Gateway and Lambda to return image
body: <p>Say I have this HTML:</p>
  
  <pre><code>&lt;img src="http://example.com/pic"/&gt;
  </code></pre>
  
  <p>What I would like to do is have example.com/pic map to an AWS API Gateway endpoint. </p>
  
  <p>That endpoint would then call a lambda function. </p>
  
  <p>That lambda function would read a random image from an s3 bucket and return it.</p>
  
  <p>So my aim is to use a STANDARD HTML image tag and end up with an image from an s3 bucket but going via some decision code in the lambda to decide the image to return.</p>
  
  <p>I know you can use s3 to serve static content directly (hence the lambda to make the decision about what image). I also know I could do stuff in the lambda like b64 encode the response and then handle it on the client but I am aiming to use the standard HTML IMG tag.</p>
  
  <p>Is this possible?</p>
  
  <p>I've tried using the ResponseStreamHandler (Java SDK) for the lambda and returning the byte array of the image and also added the API gateway config to not map the output to JSON, but nothing seems to work!</p>