Skip to main content
Version: 2.12

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.

amazon-cloudfront

Prerequisites

Before diving into configuration, make sure that you have met the prerequisites.

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. cloudFront-console

Origin Configuration

origin

  • 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. default-cache
Cache key and origin requests Configuration
  • Choose Cache policy and origin request policy.

  • Click on Create Cache Policy & configure it as shown below. cache-policy-01 cache-policy-02

  • 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. disable-waf

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. error-pages

  • Select 404: Not Found as the HTTP Error Code, set the Error Caching Minimum TTL to 3 seconds, and click the Create button. custom-error-response

  • Wait until the distribution is deployed. Once it is deployed, you can note your CloudFront Domain Name.

    cloudfront

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.

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 is stream01, the CloudFront playback URL will be like:

    http://d3m1pdd4lln4vj.cloudfront.net/play.html?id=stream01&playOrder=hls

    cloudfront-play

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 is stream001, the CloudFront playback URL will be like:

    http://d3m1pdd4lln4vj.cloudfront.net/play.html?id=stream001&playOrder=ll-hls

    ll-hls-play