Amazon CloudFront media streaming tutorials

Customers use Amazon CloudFront to stream video to viewers across the globe using a wide variety of protocols that are layered on top of HTTP.

The Amazon Content Delivery Network (CDN) can be used with AWS Elemental Media Services to implement two different types of video streaming. First, we will take a look at on-demand streaming of content stored in Amazon Simple Storage Service (Amazon S3). After that, we’ll examine live streaming of events or 24x7 channels.

For best practices, read the Amazon CloudFront for Media White Paper.

Building Serverless Video Workflows (58:42)

On-Demand streaming

In the on demand streaming case, your video content is stored in Amazon 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, AWS Elemental MediaConvert for file-based 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. 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 television or connected device. AWS Elemental MediaConvert will take care of this for you. MediaConvert takes content from S3, transcodes it per your request, and stores the result back in S3. Transcoding processes video files, creating compressed versions of the original content to reduce its size, change its format, or increase playback device compatibility. Again, you can manage this process from the AWS Management Console, the command line, or via the MediaConvert APIs.

With your content safely stored and available in the formats required by your users, the next step is global delivery with Amazon CloudFront. The Amazon Content Delivery Network caches content at the edges for low latency and high throughput video delivery. Its 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 on a pay-as-you-go basis (see the CloudFront pricing to learn more).

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. The CDN 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 that would never be seen is still downloaded and you are paying for it.

The second option is almost always preferred. A family of video streaming protocols including Apple’s HTTP Live Streaming (HLS), Dynamic Adaptive Streaming over HTTP (DASH), Microsoft’s Smooth Streaming (MSS), 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. With this option, you only pay for what the viewer watches, you don’t waste user’s bandwidth, and users get to see the desired content more quickly.

You will need to do a little more work in order to implement the second option. First, you use MediaConvert 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. Then, you point the CloudFront distribution at the manifest. Finally, to play the live stream, embed the manifest URL in the players that your users will play your live stream with. For example, to play a live stream for which the manifest file is myStream/playlist.m3u8 and the CloudFront distribution is, you embed the following URL in players:

The “Video on Demand on AWS” page provides best practices and guidance to consider when implementing a video on demand workflow on the AWS Cloud, and introduces an AWS solution that automatically provisions the services necessary to build a scalable, distributed architecture that ingests, stores, processes, and delivers video content.

Live streaming

In the live streaming case, your content represents either live events or 24x7 live channel delivery. Examples of the first include broadcasters and content aggregators streaming sports tournaments, awards ceremonies, keynote addresses and other highly viewed live events. Examples of the latter include studios, broadcasters and pay TV service operators looking to package and deliver live linear channels over the Internet directly to their audiences, without a third-party distribution platform.

You can use AWS to cost-effectively broadcast live content to a global audience by following a few simple steps.

The first step is live video processing. For this you can use AWS Elemental MediaLive, which encodes your live video streams in real-time, taking a larger-sized live video source – for example, coming from an on-premises encoder like AWS Elemental Live - and compressing it into smaller versions for distribution to your viewers. For the second step, you have two options depending on your use case. You can use a just-in-time packaging origin like AWS Elemental MediaPackage to convert video content from a single format to multiple formats and securely package it for different device types. MediaPackage makes it easy to implement popular video features for viewers (start-over, pause, rewind, etc.), like those commonly found on DVRs. It can also protect your content using Digital Rights Management (DRM). Alternatively, if the encoder is already putting the content in the format required by all of your end viewer targeted devices, you can use a high performance scalable origin like AWS Elemental MediaStore. MediaPackage and MediaStore deliver the content to Amazon CloudFront, which will route it to the audience that’s viewing the live event.

Once your solution is up and running, the live event can be broadcast around the global in a scalable, cost-effective fashion. The CDN can accommodate an audience that varies in size and can handle “flash crowds”.

The “Live Video Streaming” page provides best practices and guidance to consider when choosing a live video streaming workflow on the AWS Cloud, and introduces an AWS solution that automatically provisions the services necessary to build a highly available and cost-effective architecture that delivers an exceptional real-time viewing experience.

Media case studies

Customers use Amazon CloudFront to stream video to viewers across the globe using a wide variety of protocols that are layered on top of HTTP.

Learn how to get started with Amazon CloudFront for free

Visit the getting started page
Ready to build?
Get started with Amazon CloudFront
Have more questions?
Contact us