We are getting lots of questions about how to publish live HLS streams using Amazon CloudFront with Ant Media Server. Here is the tutorial that explains how to publish live HLS streams using Amazon CloudFront.

As the speed of the internet increases, live streaming applications are getting more popular and most of the time, these applications are designed and target to serve a huge number of audiences with acceptable latency figures as the nature of HLS. So how would you cope with the required capacity and load? One option is setting up a scaling solution which you need to bear with its cost which is due to scaling up your infrastructure and/or processing power. Another option is to use CDNs which helps to replicate your HLS stream via caching capability, therefore it is way more cost-effective than scaling up.

In this blog post, we will explain how to publish HLS stream to millions using CloudFront with Ant Media Server. Let’s start with some definitions.

What is HLS?

HTTP Live Streaming (also known as HLS) is an HTTP-based adaptive bitrate streaming communications protocol developed by Apple Inc. and released in 2009. Support for the protocol is widespread in media players, web browsers, mobile devices, and streaming media servers[1].

What is CDN?

A content delivery network or content distribution network (CDN) is a geographically distributed network of proxy servers and their data centers. The goal is to provide high availability and performance by distributing the service spatially relative to end-users.[2] For more details, please have a look at our blog post about CDNs.

What is Amazon CloudFront?

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.

Now let’s publish an HLS stream using CloudFront in Ant Media Server.

Publish HLS stream to millions using CloudFront with Ant Media Server

Requirements:

  • Ant Media Server is installed on your server.
  • You have an account in AWS console.

Step 1:

Click Create Distribution in AWS CloudFront console:

CloudFront with Ant Media Server

Step 2:

Click Get Started which is under Web section:

CloudFront

Step 3:

Fill the form as in the screenshot below:

hls stream with cloudfront

Origin Domain Name is your server domain where Ant Media Server is installed.

Origin Path is the name of the Ant Media Server application. Ant Media Server installation comes with two sample applications: WebRTCAppEE and LiveApp. In this tutorial, we used WebRTCAppEE.

HTTP Port is 5080.

Origin Protocol Policy is set as HTTP so that you don’t need SSL. If you select HTTPS, then you need to set up SSL.

Step 4:

Fill Default Cache Behavior Settings as in the screenshot:

using cloudfront with antmedia

In this screen, all the fields are set to their default values, except Query String Forwarding and Caching. This field needs to be set to Forward all, cache based on all.

Step 5:

Don’t change other values in the screen. Now click Create Distribution:

cloudfront interface  Distribution will be created and listed in the CloudFront console:

cloudfront console

Step 6:

Now we will setup cache duration to 3 sec. Click the distribution listed in the CloudFront console. You will see the detail screen as in the screenshot below:

Publishing HLS Stream to Millions Using CloudFront with Ant Media Server 1

Click Error Pages tab and in this tab click Create Custom Error Response:

Publishing HLS Stream to Millions Using CloudFront with Ant Media Server 2

Select 404: Not Found as HTTP Error Code and set Error Caching Minimum TTL as 3 sec. Then click Create button. Error response will be listed as below:

how to secure cloudfront hls distribution

Step 7:

Wait until the distribution is Deployed. Then note your CloudFront Domain Name.

Publishing HLS Stream to Millions Using CloudFront with Ant Media Server 3

Step 8:

Publish a live stream in Ant Media Server as described in here. Note the Stream Id. Create an HLS play stream URL using your CloudFront Domain Name in the following format:

http://your_cloud_front_domain_name/play.html?id=your_stream_id&playOrder=hls

It will be something like:

http://d2fjqa1eytj81z.cloudfront.net/play.html?id=6241346589939&playOrder=hls

Launch this URL in your browser. Now you will see your stream is playing. This stream is distributed by the CDN.

This concludes our blog post about CloudFront with Ant Media Server. We hope this tutorial is helpful for you 🙂 Please feel free to send an email (contact @ antmedia.io) or contact us directly at https://antmedia.io in case of any question.

    References:

    [1]https://en.wikipedia.org/wiki/HTTP_Live_Streaming

    [2]https://en.wikipedia.org/wiki/Content_delivery_network

    [3]https://aws.amazon.com/cloudfront/