Serving images through AWS Api Gateway from Serverless Lambda_proxy function

Sitecore MVP & Principal Developer at Valtech
Valtech, UK

april 18, 2018

In another post I mentioned the neat features now available in AWS: Serverless templates. As part of an experiment I thought it would be interesting to see how you could put a light security layer over S3 so that media requests stream from S3 if a user logs in.

The WebApi template  already ships with an S3 proxy controller. Tweaking this slightly allowed me to stream or download the image:Screen Shot 2019-07-03 at 10.50.05 AM.png

The issue I ran into was accessing images via the endpoint you then get in API Gateway – images were getting encoded so wouldn’t render in the browser.

The solution:

  • In the settings for your api gateway, add the Binary Media Type: */*
  • On the {proxy+} method ‘Method Response’ add a 200 response header and add a header Content-Type. Finally publish your api

The second step here may not be necessary but I found the */* didn’t kick in until I made the change.

Original article was posted on Boro2g Blog: Serving images through AWS API Gateway

Enkele voorbeelden van onze samenwerking

Neem contact op

Let's reinvent the future