AWS News Blog

Using Amazon CloudFront for Video Streaming

Voiced by Polly

March 2018 — For updated information on this topic, please visit this blog post.

Many AWS customers use Amazon CloudFront to stream videos to various devices. As you may know,
video streaming can be implemented using a wide variety of protocols that are layered on top of HTTP. As is the case with just about every aspect of AWS, we do our best to provide our customers with more than one option, and video streaming is certainly no exception.

In this post I would like to show you how multiple AWS services, combined with some third-party software, can be used to implement two different types of video streaming. First we will take a look at on-demand streaming of content stored in Amazon S3. After that, we’ll examine live streaming of events.

On-Demand Streaming
In the on-demand streaming case, your video content is stored in S3. Your viewers can choose to watch it at any desired time, hence the name on-demand. A complete on-demand streaming solution typically makes use of Amazon S3 for storage, the Amazon Elastic Transcoder for video processing, and Amazon CloudFront for delivery.

Amazon S3 is an excellent storage facility for your video assets. It is infinitely scalable, has built-in redundancy, and is available to you on a pay-as-you-go basis. In other words, your storage costs will start out very low, and then rise in proportion to the amount of video that you store. You can read about Amazon S3 pricing to learn more. You can upload your content to S3 in a number of different ways. You can start by using the AWS Management Console when your volume is low, and then move to a more automated system as your volume increases. It is very easy to use S3 from the console. After you create your AWS account, you simply log in, create an S3 bucket, and then upload your content. If you want to implement an automated system, you can use the AWS Command Line Interface in your own scripts or the Amazon S3 APIs in your own code.

Once uploaded, you may need to convert your video into the size, resolution, or format needed by a particular video player or mobile device. The Amazon Elastic Transcoder will take care of this for you. The Elastic Transcoder takes content from one S3 bucket, transcodes it per your request, and stores the result in a second S3 bucket. Again, you can manage this process from the AWS Management Console,  the command line, or via the Elastic Transcoder APIs. You will need to learn a little bit about pipelines, jobs, and presets in order to make effective use of the Elastic Transcoder.

With your content safely stored and available in the formats required by your users, the next step is global delivery. This is a job for Amazon CloudFront. This service gives you scalable global delivery at a low price point. Because CloudFront caches content at the edges, your customers will experience uninterrupted video playback with minimal delays due to buffering. CloudFront’s scalability means that you can serve up as much or as little video as you want. You can handle unexpected spikes in demand with ease, again on a pay-as-you-go basis (see the CloudFront pricing to learn more). You will need to learn about CloudFront distributions as part of this step.

At this point our story line forks, and you have two options.  You can deliver the entire video file to the device before playing it, or you can stream it to the device.

The first option is very easy to implement and is supported by just about every mobile device and desktop.  All you need to do is to put your content in an S3 bucket and create a CloudFront distribution that points to the bucket. Your user’s video player will use CloudFront URLs (accessible as part of the distribution) to request the video file. The request will be directed to the best edge location, based on the user’s location. CloudFront will serve the video from its cache, fetching it from the S3 bucket if it is not already cached. This option has a couple of downsides. It makes inefficient use of your viewer’s bandwidth. If the user doesn’t bother to watch the entire video, content would never be seen is still downloaded. Skipping ahead or fast-forwarding also necessitates downloading of content that may never be seen.

The second option is almost always preferred. A newer family of video streaming protocols including Apple’s HTTP Live Streaming (HLS), Microsoft’s Smooth Streaming, (SS) and Adobe’s HTTP Dynamic Streaming (HDS) improve the user experience by delivering video as it is being watched, generally fetching content a few seconds ahead of when it will be needed. Playback starts more quickly, fast-forwarding is more efficient, and the overall user experience is smoother. Mobile users appreciate this option because it doesn’t waste their bandwidth and they get to see the desired content more quickly.

You will need to do a little more work in order to implement the second option. Use the Elastic Transcoder to convert your video files to HLS format (the most widely supported streaming protocol). This will split the video into short segments, and will also create a manifest file. The player uses the manifest file to fetch and play the segments as needed.

The good folks behind JW Player have written a two part tutorial to show you how to use S3, Elastic Transcoder, and CloudFront to prepare and deliver files to their player. Their blog posts, Encoding HLS With Amazon Elastic Transcoder and Delivering HLS With Amazon CloudFront, will help you to get started.

Live Streaming
In the live streaming case, your content represents a live event such as a business meeting, a Mars landing, or a sporting event.

You can use AWS to cost-effectively broadcast live content to a global audience by following a few simple steps. We have worked with several vendors of streaming software to create step-by-step tutorials. The details vary by vendor and technology, but they all follow the same basic design. An Amazon EC2 instance is created and used as the basis for a CloudFront download distribution. The instance will run a streaming server that supports an HTTP-based video streaming protocol such as HLS, SS, or HDS.

The streaming server (Wowza Media Server is available in the AWS Marketplace and is a good example) will accept incoming streams from the live event, convert them to the supported streaming protocols, and deliver the content to CloudFront where it will be routed to the audience that’s viewing the live event.

Once the stack is up and running, the live event can be broadcast around the global in a scalable, cost-effective fashion. Even better, CloudFront can easily accommodate an audience that varies in size, and can even handle “flash crowds” with ease. After the event concludes, you can shut down the EC2 instance to avoid continued charges, making this a true pay-as-you-go solution.

Here are three tutorials to get you started with Live Streaming:

These tutorials show you how to use AWS CloudFormation to model and launch a “stack” for live streaming. Once created, the stack can be used over and over again, making it easy for you to handle as many live events as you would like.

Attend Our Conference
Our “Digital Media in the AWS Cloud” conference will take place on October 10 in West Hollywood, California.  At this event, you can learn how AWS can meet your media ingest, storage, processing, and content delivery needs in a scalable and cost-effective fashion. The event is free but space is limited and you need to register now if you would like to attend,

Learn More at Our Webinars
In order to help you to better understand the basics of video streaming and how CloudFront can help you to implement it, we are running a series of three webinars this month:

— Jeff;

Modified 3/12/2021 – In an effort to ensure a great experience, expired links in this post have been updated or removed from the original post.
Jeff Barr

Jeff Barr

Jeff Barr is Chief Evangelist for AWS. He started this blog in 2004 and has been writing posts just about non-stop ever since.