Try Live Demo

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 targeted 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 help 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 streams to millions using CloudFront with Ant Media Server.

Table of Contents

  • What is HLS?
  • What is CDN?
  • What is Amazon CloudFront?
  • 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 Streaming Protocol) is an HTTP-based adaptive bitrate streaming communications protocol developed by Apple Inc. and released in 2009. Support for the HLS Streaming Protocol is widespread in media players, web browsers, mobile devices, and streaming media servers.

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, and high transfer speeds, all within a developer-friendly environment.

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

How to Publish HLS stream to millions using CloudFront with Ant Media Server

To Publish an HLS stream, There are some Requirements:

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

Step 1:

Click Create Distribution in AWS CloudFront console:

Cloudfront Distribution

Step 2:

Fill the form as in the screenshot below:

Cloudfront distribution settings

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 3:

Fill Default Cache Behavior Settings as in the screenshot:

Screenshot 57

In this screen, all the fields are set to their default values, except cache policy. You need to create custom policy by clicking on create policy field and settings should be like in below image.

Cloudfront cache policy

Step 4:

Disable Web Application Firewall (WAF) settings.

waf ss

Disable WAF

After that do not change any other settings and now click Create Distribution:

Cloudfront settings  The distribution will be created and listed in the CloudFront console:

Screenshot 59

Step 5:

Now we will setup cache duration to 3 sec. Click the distribution listed in the CloudFront console and click the Error Pages tab and in this tab click Create Custom Error Response:

Cloudfront custom error

Select 404: Not Found as HTTP Error Code and set Error Caching Minimum TTL as 3 sec then click the Create button.

Custom error page settings

Step 6:

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

Cloudfront Distribution

Step 7:

Publish a live stream in Ant Media Server as described 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://d3v4y16wxjyt6s.cloudfront.net/play.html?id=061715642936790404147981&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://mirror.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/

    chatsimple
    Warning: Undefined array key "promocode" in /home/mirror.antmedia.io/public_html/wp-content/themes/hestia-child/footer.php on line 70