Creating a Video streaming service in AWS
Hey Reader,
My name is Akshay, and I am working as Senior Developer at Luxoft India. With the ever increasing demand of cloud computing Luxoft provided me ample opportunity to groom myself in AWS, the following article provided was inspired as part of one of the requirements in Luxoft. Here in this article I will be explaining how we can build a video streaming services that we can use to serve our content to the people around the world and the architecture that we are going to take up is very simple. We are going to use a S3 bucket to host our videos and then we are going to use cloudfront as our content delivery network to help us distribute our video content.
What is Cloudfront and S3?
Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment. We will be discussing further about cloudfront in the article.
An Amzon S3 bucket is a public cloud storage resource available in AWS referred as Simple Storage Service(S3) This service provide storages based on object and these are stored in bucket.
Here in this we are majorly going to talk about cloufront and how to use it to implement the video streaming services using it.
Understanding AWS Cloudfront
Amazon CloudFront is a web service that speeds up distribution of our static and dynamic web content, such as .html, .css, .js, and image files, to our users. CloudFront delivers our content through a worldwide network of data centres called edge locations.
Cloudfront is content delivery Network CDN service within AWS that has a lot of edge locations around the world and they are connected by AWS’s in house backbone network that can deliver data between them with a vey low latency and that’s what make the streaming fast. This is how cloudfront works.
Consider a scenario where we have a S3 bucket in Europe that’s being used to host our videos and then we configure cloudfront on top of that. Let’s say we have a user number one in Asia who wants to watch our video then the actual location that’s closest to that user will fetch the data from the S3 bucket and then deliver that to user number one and now lets say 20 minutes later user number two within the region wants to watch our video as well this time the actual location doesn’t need to go back to the S3 bucket to get the content because it catches it within the actual location. This time around the actual location can just serve the cache content to use number two so that’s what makes it really fast and this is exactly what we are going to build in this article.
Step by step Guide to build a video streaming service
1> Open homepage of AWS Console and create a S3 bucket to host our video. Type S3 in Search box and then create a bucket with some meaningful name. Make sure to make the bucket as private, by checking the box of “BLOCK ALL PUBLIC ACCESS” don’t uncheck it. Making it private is more secure way as we only allow the cloudfront to have access to it if users want to access the video directly from the HD bucket we are going to plug it and keep it as private.
Keep the bucket versioning and Default encryption as “Enable”. Hit “Create Bucket”.
2> After successful creation of bucket, we will create our cloudfront and configure that to access the OSD bucket and the videos within it that we upload. Type “Cloudfront” in the search box and open it. Before configuring it we need to create an origin Access Control setting for our cloudfront distribution to use.
Open the origin access settings. Create a control setting providing the details as per choice.
Check sign requests and click create.
Now click on Distribution section and then create a distribution. Below are some important setting to be taken care.
Choose the SD bucket we just created earlier and then in Origin access select as per above:
As per the Warning we must update the S3 bucket policy which can be done later after saving this setting.
For Viewer, Check on Redirect HTTP to https, this means is that we are just going to enable encryption in transit to keep our viewer connection safe secured so it’s a good practice to do so. Rest remains the defaults. Click create distribution in the end.
The Deployment might take sometime meanwhile update the S3 bucket policy.
Click on “Edit” and create the policy.
After successful deployment, we would be ready to test out the URL. So go to cloudfront Distributions that we just created and check status if its enabled or not.
In the S3 bucket upload a video to it in Upload section.
From the cloudfront copy the domain name and paste in new tab with a slash go back to the S3 bucket and copy the object key paste after slash and hit enter. This would start to play the video on browser. This confirms our S3 is working fine with cloudfront.
Conclusion:
In this article I have tried to explain the main concepts of cloudfront and its application towards how we can build a video streaming services. In my next article I will explaining its frontend and AWS S3 policy creation in detail. So stay tuned for my next article in upcoming topic. Do let me know in case of any queries in comments below.
Thanks for reading.