Kontakt

Serving images through AWS Api Gateway from Serverless Lambda_proxy function

Sitecore MVP & Principal Developer at Valtech
Valtech, UK

18. April 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

Kontakt

Wir freuen uns auf Ihre Nachricht! Bitte füllen Sie das Formular aus. Der zuständige Mitarbeiter unseres Büros wird sich dann mit Ihnen in Verbindung setzen.
Sollten Sie ein alternatives Format und/oder Unterstützung bei der Kommunikation benötigen, um uns Feedback zu geben, wenden Sie sich bitte an Sheree Atcheson.

Let's reinvent the future