We are getting lots of questions about how to publish live HLS stream using Amazon CloudFront with Ant Media Server. Here is the tutorial explains how to do it.
As the speed of internet increases, live streaming applications are getting more popular and most of the time, these applications are designed and target to serve huge number of audiences with acceptable latency figures as nature of HLS. So how would you cope with 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 replicating 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. Lets 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.
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. 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
- Ant Media Server is installed on your server.
- You have an account in AWS console.
Click Create Distribution in AWS CloudFront console:
Click Get Started which is under Web section:
Fill the form as in the screenshot below:
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.
Fill Default Cache Behavior Settings as in the screenshot:
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.
Don’t change other values in the screen. Now click Create Distribution:
Distribution will be created and listed in the CloudFront console:
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:
Click Error Pages tab and in this tab click Create Custom Error Response:
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:
Wait until the distribution is Deployed. Then note your CloudFront Domain Name.
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:
It will be something like:
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.