Search code examples
javaamazon-web-servicesamazon-s3amazon-cloudfrontvideo.js

Media download/upload in S3 + Cloudfront


I've got a frontend built with angularJS that speaks to a backend in Java.

I have all code up and running which uploads and downloads images from S3 to my app.

I can also access videos in S3 and display them with the videojs library.

Performance-wise, I've been reading a bit about Amazon Cloudfront. I've already implemented the ETag cache in my code and it works well.

However, what is my next step to integrate this Cloudfront? All tutorials I've looked into only show static files. Would I need to make additional code changes or is it only a matter of configuration on my AWS stack? One of the key points I want to achieve and learn is how to make the videos being streamed instead of having them downloaded fully into the client.


Solution

  • CloudFront is a Content Delivery Network (CDN). You create a distribution and you tell it which S3 bucket holds the files you want to serve. Then, if you have a domain name you can add a CNAME cdn.yourdomain.com and map it to the domain offered to you by CloudFront.

    Users visiting cdn.yourdomain.com/yourfile will effectively get the cached versions instead of downloading them from S3.

    You can also create an RMTP distribution for streaming, which allows users to play the video while it's being downloaded and it uses the Adobe Flash Media RMTP protocol but, be cautious: as reported here, CloudFront is discontinuing support for RTMP distributions on December 31, 2020.