Amazon CloudFront
A content delivery or distribution network (CDN) is a geographically distributed network of proxy servers and their data centers. The goal of a CDN is to provide high availability and performance by distributing the service spatially relative to end-users.
In this document, we will learn how to configure Amazon CloudFront to play HLS & LL-HLS streams from the Ant Media Server.
What is Amazon CloudFront?
Amazon CloudFront is a web service that speeds up the distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you're serving with CloudFront, the request is routed to the edge location that provides the lowest latency (time delay) to deliver content with the best possible performance.
Prerequisites
Before diving into configuration, make sure that you have met the prerequisites.
- An Amazon Web Server account.
- A running instance of Ant Media Server, either launched from the AWS Marketplace or installed manually.
- HLS is enabled for your Ant Media Server instance.
- The LL-HLS plugin is installed if you want to play the streams with LL-HLS.
Configure Amazon CloudFront
Now that we have fulfilled the prerequisites, let's configure CloudFront to deliver the Ant Media Server streams.
Create Distribution
- Log in to your AWS account & go to the Amazon CloudFront.
- Click Create Distribution.
Origin Configuration
- Origin domain: Here, you need to enter the domain name of your Ant Media Server instance.
- Protocol: You can choose HTTP (5080) or HTTPS (5443). If you choose HTTPS, then SSL should be enabled.
- Origin path: The name of your Ant Media Server application. In this example, I'm using live.
Default Cache Behavior Configuration
- Fill the Default Cache Behavior Settings as shown below.
Cache key and origin requests Configuration
-
Choose Cache policy and origin request policy.
-
Click on Create Cache Policy & configure it as shown below.
-
After the policy is created, attach it to the
Cache policy
Web Application Firewall (WAF) Configuration
- Disable the Web Application Firewall (WAF) protection for the distribution.
Now, the distribution will be created and listed in the CloudFront console.
Configuring Error Pages
-
Click the distribution listed in the CloudFront console, then click the Error Pages tab. In this tab, click Create Custom Error Response.
-
Select 404: Not Found as the HTTP Error Code, set the Error Caching Minimum TTL to 3 seconds, and click the Create button.
-
Wait until the distribution is deployed. Once it is deployed, you can note your CloudFront Domain Name.
Publish Live Stream with Ant Media Server
Now that we have everything set, let’s publish a live stream in Ant Media Server following the Publish Live Stream instructions and note the Stream Id.
- For this demo, we are going to publish a RTMP stream.
Play the Live Stream with HLS
Create the HLS playback URL using your Amazon CloudFront in the below format:
http://your_cloud_front_domain_name/play.html?id=your_stream_id&playOrder=hls
-
Example: If the
streamId
isstream01
, the CloudFront playback URL will be like:http://d3m1pdd4lln4vj.cloudfront.net/play.html?id=stream01&playOrder=hls
Play the Live Stream with LL-HLS
Create the LL-HLS playback URL using your Amazon CloudFront in the below format:
http://your_cloud_front_domain_name/play.html?id=your_stream_id&playOrder=ll-hls
-
Example: If the
streamId
isstream001
, the CloudFront playback URL will be like:http://d3m1pdd4lln4vj.cloudfront.net/play.html?id=stream001&playOrder=ll-hls