

# Video on demand and live streaming video with CloudFront
<a name="on-demand-streaming-video"></a>

You can use CloudFront to deliver video on demand (VOD) or live streaming video by using any HTTP origin. One way you can set up video workflows in the cloud is by using CloudFront together with [AWS Media Services](https://aws.amazon.com/media-services/).

**Topics**
+ [About streaming video](#StreamingVideo)
+ [Deliver video on demand with CloudFront](on-demand-video.md)
+ [Deliver video streaming with CloudFront and AWS Media Services](live-streaming.md)
+ [Media quality-aware resiliency](media-quality-score.md)

## About streaming video
<a name="StreamingVideo"></a>

You must use an encoder to package video content before CloudFront can distribute the content. The packaging process creates *segments* that contain your audio, video, and captions content. It also generates manifest files, which describe in a specific order what segments to play and when. Common package formats are MPEG DASH, Apple HLS, Microsoft Smooth Streaming, and CMAF.

**VOD streaming**  
For VOD streaming, your video content is stored on a server and viewers can watch it at any time. To make an asset that viewers can stream, use an encoder, such as [AWS Elemental MediaConvert](https://docs.aws.amazon.com/mediaconvert/latest/ug/getting-started.html), to format and package your media files.   
After your video is packaged into the right formats, you can store it on a server or in an Amazon S3 bucket, and then deliver it with CloudFront as viewers request it.

**Live video streaming**  
For live video streaming, your video content is streamed real time as live events happen, or is set up as a 24x7 live channel. To create live outputs for broadcast and streaming delivery, use an encoder such as AWS Elemental MediaLive, to compress the video and format it for viewing devices.   
After your video is encoded, you can store it in AWS Elemental MediaStore or convert it into different delivery formats by using AWS Elemental MediaPackage. Use either of these origins to set up a CloudFront distribution to deliver the content. For specific steps and guidance for creating distributions that work together with these services, see [Serve video by using AWS Elemental MediaStore as the origin](live-streaming.md#video-streaming-mediastore) and [Serve live video formatted with AWS Elemental MediaPackage](live-streaming.md#live-streaming-with-mediapackage).

Wowza and Unified Streaming also provide tools that you can use for streaming video with CloudFront. For more information about using Wowza with CloudFront, see [Bring your Wowza Streaming Engine license to CloudFront live HTTP streaming](https://www.wowza.com/docs/how-to-bring-your-wowza-streaming-engine-license-to-cloudfront-live-http-streaming) on the Wowza documentation website. For information about using Unified Streaming with CloudFront for VOD streaming, see [CloudFront](https://docs.unified-streaming.com/documentation/vod/cloud/amazon/amazon-cloudfront.html) on the Unified Streaming documentation website.

# Deliver video on demand with CloudFront
<a name="on-demand-video"></a>

To deliver video on demand (VOD) streaming with CloudFront, use the following services:
+ Amazon S3 to store the content in its original format and to store the transcoded video.
+ An encoder (such as AWS Elemental MediaConvert) to transcode the video into streaming formats.
+ CloudFront to deliver the transcoded video to viewers. For Microsoft Smooth Streaming, see [Configure video on demand for Microsoft Smooth Streaming](#on-demand-streaming-smooth).

**To create a VOD solution with CloudFront**

1. Upload your content to an Amazon S3 bucket. To learn more about working with Amazon S3, see [the Amazon Simple Storage Service User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/).

1. Transcode your content by using a MediaConvert job. The job converts your video into the formats required by the players that your viewers use. You can also use the job to create assets that vary in resolution and bitrate. These assets are used for adaptive bitrate (ABR) streaming, which adjusts the viewing quality depending on the viewer’s available bandwidth. MediaConvert stores the transcoded video in an S3 bucket.

1. Deliver your converted content by using a CloudFront distribution. Viewers can watch the content on any device, at any time. 

## Configure video on demand for Microsoft Smooth Streaming
<a name="on-demand-streaming-smooth"></a>

You have the following options for using CloudFront to distribute video on demand (VOD) content that you’ve transcoded into the Microsoft Smooth Streaming format:
+ Specify a web server that runs Microsoft IIS and supports Smooth Streaming as the origin for your distribution.
+ Enable Smooth Streaming in the cache behaviors of a CloudFront distribution. Because you can use multiple cache behaviors in a distribution, you can use one distribution for Smooth Streaming media files as well as other content. 

**Important**  
If you specify a web server running Microsoft IIS as your origin, do *not* enable Smooth Streaming in the cache behaviors of your CloudFront distribution. CloudFront can’t use a Microsoft IIS server as an origin if you enable Smooth Streaming as a cache behavior.

If you enable Smooth Streaming in a cache behavior (that is, you do not have a server that is running Microsoft IIS), note the following:
+ You can still distribute other content using the same cache behavior if the content matches the value of **Path Pattern** for that cache behavior.
+ CloudFront can use either an Amazon S3 bucket or a custom origin for Smooth Streaming media files. CloudFront cannot use a Microsoft IIS Server as an origin if you enable Smooth Streaming for the cache behavior. 
+ You cannot invalidate media files in the Smooth Streaming format. If you want to update files before they expire, you must rename them. For more information, see [Add, remove, or replace content that CloudFront distributes](AddRemoveReplaceObjects.md).

For information about Smooth Streaming clients, see [Smooth Streaming](https://learn.microsoft.com/en-us/shows/iis-net-site-videos/smooth-streaming) on the Microsoft documentation website.

**To use CloudFront to distribute Smooth Streaming files when a Microsoft IIS web server isn’t the origin**

1. Transcode your media files into Smooth Streaming fragmented MP4 format.

1. Do one of the following:
   + **If you’re using the CloudFront console:** When you create or update a distribution, enable Smooth Streaming in one or more of the distribution’s cache behaviors.
   + **If you’re using the CloudFront API:** Add the `SmoothStreaming` element to the `DistributionConfig` complex type for one or more of the distribution’s cache behaviors.

1. Upload the Smooth Streaming files to your origin.

1. Create either a `clientaccesspolicy.xml` or a `crossdomainpolicy.xml` file, and add it to a location that is accessible at the root of your distribution, for example, `https://d111111abcdef8.cloudfront.net/clientaccesspolicy.xml`. The following is an example policy:

   ```
   <?xml version="1.0" encoding="utf-8"?>
   <access-policy>
   <cross-domain-access>
   <policy>
   <allow-from http-request-headers="*">
   <domain uri="*"/>
   </allow-from>
   <grant-to>
   <resource path="/" include-subpaths="true"/>
   </grant-to>
   </policy>
   </cross-domain-access>
   </access-policy>
   ```

   For more information, see [Making a Service Available Across Domain Boundaries](https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/cc197955(v=vs.95)) on the Microsoft Developer Network website. 

1. For links in your application (for example, a media player), specify the URL for the media file in the following format:

   `https://d111111abcdef8.cloudfront.net/video/presentation.ism/Manifest`

# Deliver video streaming with CloudFront and AWS Media Services
<a name="live-streaming"></a>

To use AWS Media Services with CloudFront to deliver live content to a global audience, see the following guidance.

Use [AWS Elemental MediaLive](https://docs.aws.amazon.com/medialive/latest/ug/getting-started.html) to encode live video streams in real time. To encode a large video stream, MediaLive compresses it into smaller versions (*encodes*) that can be distributed to your viewers.

After you compress a live video stream, you can use either of the following two main options to prepare and serve the content:
+ **Convert your content into required formats, and then serve it** – If you require content in multiple formats, use [AWS Elemental MediaPackage](https://aws.amazon.com/mediapackage/) to package the content for different device types. When you package the content, you can also implement extra features and add digital rights management (DRM) to prevent unauthorized use of your content. For step-by-step instructions for using CloudFront to serve content that MediaPackage formatted, see [Serve live video formatted with AWS Elemental MediaPackage](#live-streaming-with-mediapackage).
+ **Store and serve your content using scalable origin** – If MediaLive encoded content in the formats required by all of the devices that your viewers use, use a highly scalable origin like [AWS Elemental MediaStore](https://docs.aws.amazon.com/mediastore/latest/ug/getting-started.html) to serve the content. For step-by-step instructions for using CloudFront to serve content that is stored in a MediaStore container, see [Serve video by using AWS Elemental MediaStore as the origin](#video-streaming-mediastore).

After you’ve set up your origin by using one of these options, you can distribute live streaming video to viewers by using CloudFront.

**Tip**  
You can learn about an AWS solution that automatically deploys services for building a highly available real-time viewing experience. To see the steps to automatically deploy this solution, see [Live Streaming Automated Deployment](https://docs.aws.amazon.com/solutions/latest/live-streaming/deployment.html).

**Topics**
+ [Serve video by using AWS Elemental MediaStore as the origin](#video-streaming-mediastore)
+ [Serve live video formatted with AWS Elemental MediaPackage](#live-streaming-with-mediapackage)
+ [Serve video-on-demand content with AWS Elemental MediaPackage](#live-streaming-mediapackage-vod)

## Serve video by using AWS Elemental MediaStore as the origin
<a name="video-streaming-mediastore"></a>

If you have video stored in an [AWS Elemental MediaStore](https://docs.aws.amazon.com/mediastore/latest/ug/getting-started.html) container, you can create a CloudFront distribution to serve the content.

To get started, you grant CloudFront access to your MediaStore container. Then you create a CloudFront distribution and configure it to work with MediaStore.

**To serve content from an AWS Elemental MediaStore container**

1. Follow the procedure at [Allowing Amazon CloudFront to access your AWS Elemental MediaStore container](https://docs.aws.amazon.com/mediastore/latest/ug/cdns-allowing-cloudfront-to-access-mediastore.html), and then return to these steps to create your distribution.

1. Create a distribution with the following settings:

   1. **Origin domain** – The data endpoint that is assigned to your MediaStore container. From the dropdown list, choose the MediaStore container for your live video.

   1. **Origin path** – The folder structure in the MediaStore container where your objects are stored. For more information, see [Origin path](DownloadDistValuesOrigin.md#DownloadDistValuesOriginPath).

   1. **Add custom header** – Add header names and values if you want CloudFront to add custom headers when it forwards requests to your origin.

   1. **Viewer protocol policy** – Choose **Redirect HTTP to HTTPS**. For more information, see [Viewer protocol policy](DownloadDistValuesCacheBehavior.md#DownloadDistValuesViewerProtocolPolicy).

   1. **Cache policy** and **Origin request policy** 
      + For **Cache policy**, choose **Create policy**, and then create a cache policy that’s appropriate for your caching needs and segment durations. After you create the policy, refresh the list of cache policies and choose the policy that you just created.
      + For **Origin request policy**, choose **CORS-CustomOrigin** from the dropdown list.

   For the other settings, you can set specific values based on other technical requirements or the needs of your business. For a list of all the options for distributions and information about setting them, see [All distribution settings reference](distribution-web-values-specify.md).

1. For links in your application (for example, a media player), specify the name of the media file in the same format that you use for other objects that you’re distributing using CloudFront.

## Serve live video formatted with AWS Elemental MediaPackage
<a name="live-streaming-with-mediapackage"></a>

If you formatted a live stream by using AWS Elemental MediaPackage, you can create a CloudFront distribution and configure cache behaviors to serve the live stream. The following process assumes that you have already [ created a channel](https://docs.aws.amazon.com/mediapackage/latest/ug/channels-create.html) and [added endpoints](https://docs.aws.amazon.com/mediapackage/latest/ug/channels-add-endpoint.html) for your live video using MediaPackage.

To create a CloudFront distribution for MediaPackage manually, follow these steps:

**Topics**

### Step 1: Create and configure a CloudFront distribution
<a name="live-streaming-with-mediapackage-create-dist"></a>

Complete the following procedure to set up a CloudFront distribution for the live video channel that you created with MediaPackage.<a name="live-streaming-with-mediapackage-create-dist-procedure"></a>

**To create a distribution for your live video channel**

1. Sign in to the AWS Management Console and open the CloudFront console at [https://console.aws.amazon.com/cloudfront/v4/home](https://console.aws.amazon.com/cloudfront/v4/home).

1. Choose **Create distribution**.

1. Choose the settings for the distribution, including the following:  
**Origin domain**  
The origin where your MediaPackage live video channel and endpoints are. Choose the text field, then from the dropdown list, choose the MediaPackage origin domain for your live video. You can map one domain to several origin endpoints.  
If you created your origin domain using another AWS account, type the origin URL value into the field. The origin must be an HTTPS URL.  
For example, for an HLS endpoint like `https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/abc123/index.m3u8`, the origin domain is `3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com`.  
For more information, see [Origin domain](DownloadDistValuesOrigin.md#DownloadDistValuesDomainName).  
**Origin path**  
The path to the MediaPackage endpoint from where the content is served.  
For more information about how an origin path works, see [Origin path](DownloadDistValuesOrigin.md#DownloadDistValuesOriginPath).
**Important**  
The wildcard path `*` is required to route somewhere in the CloudFront distribution. To prevent requests not matching an explicit path from routing to the real origin, create a "dummy" origin for that wildcard path.  
**Example : Creating a "dummy" origin**  

   In the following example, the endpoints `abc123` and `def456` route to the "real" origin, but requests for any other endpoint's video content route to `mediapackage.us-west-2.amazonaws.com` without the proper subdomain, which results in an HTTP `404` error.

   MediaPackage endpoints:

   ```
   https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/abc123/index.m3u8
   https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/def456/index.m3u8
   ```

   CloudFront Origin A:

   ```
   Domain: 3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com
   Path: None
   ```

   CloudFront Origin B:

   ```
   Domain: mediapackage.us-west-2.amazonaws.com
   Path: None
   ```

   CloudFront cache behavior:

   ```
   1. Path: /out/v1/abc123/* forward to Origin A
   2. Path: /out/v1/def456/* forward to Origin A
   3. Path: * forward to Origin B
   ```

   For the other distribution settings, set specific values based on other technical requirements or the needs of your business. For a list of all the options for distributions and information about setting them, see [All distribution settings reference](distribution-web-values-specify.md).

   When you finish choosing the other distribution settings, choose **Create distribution**.

1. Choose the distribution that you just created, then choose **Behaviors**.

1. Select the default cache behavior, then choose **Edit**. Specify the correct cache behavior settings for the channel that you chose for the origin. Later, you’ll add one or more additional origins and edit cache behavior settings for them.

1. Go to the [CloudFront distributions page](https://console.aws.amazon.com/cloudfront/v4/home#/distributions).

1. Wait until the value of the **Last modified** column for your distribution has changed from **Deploying** to a date and time, indicating that CloudFront has created your distribution.

### Step 2: Add Origins for the domains of your MediaPackage endpoints
<a name="live-streaming-with-mediapackage-add-endpoints"></a>

Repeat the steps here to add each of your MediaPackage channel endpoints to your distribution, keeping in mind the need to create a "dummy" origin.<a name="live-streaming-with-mediapackage-add-endpoints-procedure"></a>

**To add other endpoints as origins**

1. On the CloudFront console, choose the distribution that you created for your channel.

1. Choose **Origins**, then choose **Create origin**.

1. For **Origin domain**, in the dropdown list, choose a MediaPackage endpoint for your channel.

1. For the other settings, set the values based on other technical requirements or the needs of your business. For more information, see [Origin settings](DownloadDistValuesOrigin.md).

1. Choose **Create origin**.

### Step 3: Configure cache behaviors for all endpoints
<a name="live-streaming-with-mediapackage-create-cache-behavior"></a>

For each endpoint, you must configure cache behaviors to add path patterns that route requests correctly. The path patterns that you specify depend on the video format that you’re serving. The following procedure includes the path pattern information to use for Apple HLS, CMAF, DASH, and Microsoft Smooth Streaming formats.

You typically set up two cache behaviors for each endpoint:
+ The parent manifest, which is the index to your files.
+ The segments, which are the files of the video content.<a name="live-streaming-with-mediapackage-create-cache-behavior-procedure"></a>

**To create a cache behavior for an endpoint**

1. On the CloudFront console, choose the distribution that you created for your channel.

1. Choose **Behaviors**, then choose **Create behavior**.

1. For **Path pattern**, use a specific MediaPackage `OriginEndpoint` GUID as a path prefix.  
**Path patterns**  
For an HLS endpoint like `https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/abc123/index.m3u8`, create the following two cache behaviors:  
   + For parent and child manifests, use `/out/v1/abc123/*.m3u8`.
   + For the content segments, use `/out/v1/abc123/*.ts`.
For a CMAF endpoint like `https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/abc123/index.m3u8`, create the following two cache behaviors:  
   + For parent and child manifests, use `/out/v1/abc123/*.m3u8`.
   + For the content segments, use `/out/v1/abc123/*.mp4`.
For a DASH endpoint like `https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/abc123/index.mpd`, create the following two cache behaviors:  
   + For the parent manifest, use `/out/v1/abc123/*.mpd`.
   + For the content segments, use `/out/v1/abc123/*.mp4`.
For a Microsoft Smooth Streaming endpoint like `https://3ae97e9482b0d011.mediapackage.us-west-2.amazonaws.com/out/v1/abc123/index.ism`, only a manifest is served, so you create only one cache behavior: `out/v1/abc123/index.ism/*`.

1. For each cache behavior, specify values for the following settings:  
**Viewer protocol policy**  
Choose **Redirect HTTP to HTTPS**.  
**Cache policy and origin request policy**  
For **Cache policy**, choose **Create policy**. For your new cache policy, specify the following settings:    
**Minimum TTL**  
Set to 5 seconds or less, to help prevent serving stale content.  
**Query strings**  
For **Query strings** (in **Cache key settings**), choose **Include specified query strings**. For **Allow**, add the following values by typing them and then choosing **Add item**:  
   + Add `m` as a query string parameter that you want CloudFront to use as the basis for caching. The MediaPackage response always includes the tag `?m=###` to capture the modified time of the endpoint. If content is already cached with a different value for this tag, CloudFront requests a new manifest instead of serving the cached version.
   + If you’re using the time-shifted viewing functionality in MediaPackage, specify `start` and `end` as additional query string parameters on the cache behavior for manifest requests (`*.m3u8`, `*.mpd`, and `index.ism/*`). This way, content is served that’s specific to the requested time period in the manifest request. For more information about time-shifted viewing and formatting content start and end request parameters, see [Time-shifted viewing](https://docs.aws.amazon.com/mediapackage/latest/ug/time-shifted.html) in the *AWS Elemental MediaPackage User Guide*.
   + If you’re using the manifest filtering feature in MediaPackage, specify `aws.manifestfilter` as an additional query string parameter for the cache policy that you use with the cache behavior for manifest requests (`*.m3u8`, `*.mpd`, and `index.ism/*`). This configures your distribution to forward the `aws.manifestfilter` query string to your MediaPackage origin, which is required for the manifest filtering feature to work. For more information, see [Manifest filtering](https://docs.aws.amazon.com/mediapackage/latest/ug/manifest-filtering.html) in the *AWS Elemental MediaPackage User Guide*.
   + If you're using low-latency HLS (LL-HLS), specify `_HLS_msn` and `_HLS_part` as additional query string parameters for the cache policy that you use with the cache behavior for manifest requests (`*.m3u8`). This configures your distribution to forward the `_HLS_msn` and `_HLS_part` query strings to your MediaPackage origin, which is required for the LL-HLS blocking playlist request feature to work.

1. Choose **Create**.

1. After you create the cache policy, go back to the cache behavior creation workflow. Refresh the list of cache policies, and choose the policy that you just created.

1. Choose **Create behavior**.

1. If your endpoint is not a Microsoft Smooth Streaming endpoint, repeat these steps to create a second cache behavior.

### Step 4: Enable header-based MediaPackage CDN Authorization
<a name="live-streaming-with-mediapackage-enable-header-based-cdn-authorization"></a>

We recommend enabling header-based MediaPackage CDN Authorization between MediaPackage endpoints and the CloudFront distribution. For more information, see [Enable CDN authorization in MediaPackage](https://docs.aws.amazon.com/mediapackage/latest/ug/cdn-auth-setup.html#cdn-aut-setup-endpoint) in the *AWS Elemental MediaPackage User Guide*.

### Step 5: Use CloudFront to serve the live stream channel
<a name="live-streaming-with-mediapackage-serve-channel"></a>

After you create the distribution, add the origins, create the cache behaviors, and enable header-based CDN authorization, you can serve the live stream channel using CloudFront. CloudFront routes requests from viewers to the correct MediaPackage endpoints based on the settings that you configured for the cache behaviors.

For links in your application (for example, a media player), specify the URL for the media file in the standard format for CloudFront URLs. For more information, see [Customize the URL format for files in CloudFront](LinkFormat.md).

## Serve video-on-demand content with AWS Elemental MediaPackage
<a name="live-streaming-mediapackage-vod"></a>

If you originate your video-on-demand (VOD) content from an AWS Elemental MediaPackage origin, you can create a CloudFront distribution and configure optimized cache behaviors to serve the VOD content to viewers. The following process assumes that you have already [ created a packaging group](https://docs.aws.amazon.com/mediapackage/latest/ug/pkg-group-create.html) with a [packaging configuration](https://docs.aws.amazon.com/mediapackage/latest/ug/pkg-cfig-create.html) and [ingested an asset](https://docs.aws.amazon.com/mediapackage/latest/ug/asset-create.html) with MediaPackage.

To create a CloudFront distribution for MediaPackage manually, follow these steps:

**Topics**

### Step 1: Create and configure a CloudFront distribution
<a name="live-streaming-mediapackage-vod-create-dist"></a>

Complete the following procedure to set up a CloudFront distribution for the packaging group that you created with MediaPackage.<a name="live-streaming-with-mediapackage-create-dist-procedure"></a>

**To create a distribution for your VOD content**

1. Sign in to the AWS Management Console and open the CloudFront console at [https://console.aws.amazon.com/cloudfront/v4/home](https://console.aws.amazon.com/cloudfront/v4/home).

1. Choose **Create distribution**.

1. Choose the settings for the distribution, including the following:  
**Origin domain**  
The origin for your MediaPackage packaging group. Type the origin URL value into the text field. The origin must be an HTTPS URL.  
For example, for an HLS endpoint like `https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/def456/ghi789/index.m3u8`, the origin domain is `3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com`.  
For more information, see [Origin domain](DownloadDistValuesOrigin.md#DownloadDistValuesDomainName).  
**Origin path**  
The path from where the content is served.  
For more information about how an origin path works, see [Origin path](DownloadDistValuesOrigin.md#DownloadDistValuesOriginPath).
**Important**  
The wildcard path `*` is required to route somewhere in the CloudFront distribution. To prevent requests not matching an explicit path from routing to the real origin, create a "dummy" origin for that wildcard path.  
**Example : Creating a "dummy" origin**  

   In the following example, the packaging configurations `def456` and `321xyz` route to the "real" origin, but requests for any other video content route to `mediapackage-vod.us-west-2.amazonaws.com` without the proper subdomain, which results in an HTTP `404` error.

   MediaPackage content URLs for a single asset for a packaging group with two packaging configurations:

   ```
   https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/def456/ghi789/index.m3u8
   https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/321xyz/654uvw/index.m3u8
   ```

   CloudFront Origin A:

   ```
   Domain: 3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com
   Path: None
   ```

   CloudFront Origin B:

   ```
   Domain: mediapackage-vod.us-west-2.amazonaws.com
   Path: None
   ```

   CloudFront cache behavior:

   ```
   1. Path: /out/v1/*/def456/* forward to Origin A
   2. Path: /out/v1/*/321xyz/* forward to Origin A
   3. Path: * forward to Origin B
   ```

   For the other distribution settings, set specific values based on other technical requirements or the needs of your business. For a list of all the options for distributions and information about setting them, see [All distribution settings reference](distribution-web-values-specify.md).

   When you finish choosing the other distribution settings, choose **Create distribution**.

1. Choose the distribution that you just created, then choose **Behaviors**.

1. Select the default cache behavior, then choose **Edit**. Specify the correct cache behavior settings for the packaging configuration that you chose for the origin. Later, you'll add one or more additional origins and edit cache behavior settings for them.

1. Go to the [CloudFront distributions page](https://console.aws.amazon.com/cloudfront/v4/home#/distributions).

1. Wait until the value of the **Last modified** column for your distribution has changed from **Deploying** to a date and time, indicating that CloudFront has created your distribution.

### Step 2: Add Origins for the domains of your MediaPackage packaging groups
<a name="live-streaming-mediapackage-vod-add-endpoints"></a>

Repeat the steps here to add each of your MediaPackage packaging groups to your distribution, keeping in mind the need to create a "dummy" origin.<a name="live-streaming-mediapackage-vod-add-packaging-groups-procedure"></a>

**To add other packaging groups as origins**

1. On the CloudFront console, choose the distribution that you created for your channel.

1. Choose **Origins**, then choose **Create origin**.

1. For **Origin domain**, type in the URL for the MediaPackage packaging group.

1. For the other settings, set the values based on other technical requirements or the needs of your business. For more information, see [Origin settings](DownloadDistValuesOrigin.md).

1. Choose **Create origin**.

### Step 3: Configure cache behaviors for all packaging configurations
<a name="live-streaming-mediapackage-vod-create-cache-behavior"></a>

For each packaging configuration, you must configure cache behaviors to add path patterns that route requests correctly. The path patterns that you specify depend on the video format that you’re serving. The following procedure includes the path pattern information to use for Apple HLS, CMAF, DASH, and Microsoft Smooth Streaming formats.

You typically set up multiple cache behaviors for each packaging configuration:
+ The parent manifest, which is the index to your files.
+ The segments, which are the files of the video content. A format might use more than one extension for content, depending on your configuration. A cache behavior is needed for each extension.<a name="live-streaming-mediapackage-vod-create-cache-behavior-procedure"></a>

**To create a cache behavior for a packaging configuration**

1. On the CloudFront console, choose the distribution that you created for your channel.

1. Choose **Behaviors**, then choose **Create behavior**.

1. For **Path pattern**, use a specific MediaPackage VOD packaging configuration GUID as a path prefix. This is the second GUID in a MediaPackage VOD path.  
**Path patterns**  
For HLS content like `https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/def456/ghi789/index.m3u8`, create the following cache behaviors:  
   + For parent and child manifests, use `/out/v1/*/def456/*.m3u8`.
   + For the content segments, use `/out/v1/*/def456/*.ts` and repeat for all needed segment extensions.
For CMAF content like `https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/def456/ghi789/index.m3u8`, create the following cache behaviors:  
   + For parent and child manifests, use `/out/v1/*/def456/*.m3u8`.
   + For the content segments, use `/out/v1/*/def456/*.mp4` and repeat for all needed segment extensions.
For DASH content like `https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/def456/ghi789/index.mpd`, create the following cache behaviors:  
   + For the parent manifest, use `/out/v1/*/def456/*.mpd`.
   + For the content segments, use `/out/v1/*/def456/*.mp4`.
For a Microsoft Smooth Streaming endpoint like `https://3ae97e9482b0d011.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/abc123/def456/ghi789/index.ism/Manifest`, only a manifest is served, so you create only one cache behavior: `out/v1/*/def456/*/index.ism/*`.

1. For each cache behavior, specify values for the following settings:  
**Viewer protocol policy**  
Choose **Redirect HTTP to HTTPS**.  
**Cache policy and origin request policy**  
For **Cache policy**, choose **Create policy**. For your new cache policy, specify the following settings:    
**Minimum TTL**  
Set to 5 seconds or less, to help prevent serving stale content.  
**Query strings**  
For **Query strings** (in **Cache key settings**), choose **Include specified query strings**. For **Allow**, add the following values by typing them and then choosing **Add item**:  
   + If you’re using the manifest filtering feature in MediaPackage, specify `aws.manifestfilter` as an additional query string parameter for the cache policy that you use with the cache behavior for manifest requests (`*.m3u8`, `*.mpd`, and `index.ism/*`). This configures your distribution to forward the `aws.manifestfilter` query string to your MediaPackage origin, which is required for the manifest filtering feature to work. For more information, see [Manifest filtering](https://docs.aws.amazon.com/mediapackage/latest/ug/manifest-filtering.html) in the *AWS Elemental MediaPackage User Guide*.

1. Choose **Create**.

1. After you create the cache policy, go back to the cache behavior creation workflow. Refresh the list of cache policies, and choose the policy that you just created.

1. Choose **Create behavior**.

1. If your endpoint is not a Microsoft Smooth Streaming endpoint, repeat these steps to create a second cache behavior.

### Step 4: Enable header-based MediaPackage CDN Authorization
<a name="live-streaming-mediapackage-vod-enable-header-based-cdn-authorization"></a>

We recommend enabling header-based MediaPackage CDN Authorization between MediaPackage VOD content and the CloudFront distribution. For more information, see [Enable CDN authorization in MediaPackage](https://docs.aws.amazon.com/mediapackage/latest/ug/cdn-auth-setup.html#cdn-aut-setup-endpoint) in the *AWS Elemental MediaPackage User Guide*.

### Step 5: Use CloudFront to serve the VOD content
<a name="live-streaming-mediapackage-vod-serve-content"></a>

After you create the distribution, add the origins, create the cache behaviors, and enable header-based CDN authorization, you can serve the VOD content using CloudFront. CloudFront routes requests from viewers to the correct MediaPackage VOD content based on the settings that you configured for the cache behaviors.

For links in your application (for example, a media player), specify the URL for the media file in the standard format for CloudFront URLs. For more information, see [Customize the URL format for files in CloudFront](LinkFormat.md).

# Media quality-aware resiliency
<a name="media-quality-score"></a>

Media quality-aware resiliency (MQAR) is an integrated capability between [Amazon CloudFront](https://aws.amazon.com/cloudfront/) and [AWS Media Services](https://aws.amazon.com/media-services/). MQAR provides automated cross-Region origin selection based on Media Quality Confidence Score (MQCS). MQCS is synthesized by AWS Elemental MediaLive based on parameters that affect media quality experience perceived by viewers. You can configure CloudFront and AWS Media Services to deliver your live event streaming with high resiliency by using multiple options that you can specify in the CloudFront origin group failover criteria.

When you enable the MQAR feature for your distribution, you authorize CloudFront to automatically select the origin that is deemed to have the highest quality score. 

The quality score represents perceived media streaming quality issues from your origins, such as black frames, frozen or dropped frames, or repeated frames. For example, if your AWS Elemental MediaPackage v2 origins are deployed in two different AWS Regions, and one reports a higher media quality score than the other, CloudFront will automatically switch to the origin that reports the higher score.

To achieve this, CloudFront does the following:

1. CloudFront forwards a `GET` request to the primary MediaPackage origin, and also initiates a `HEAD` request to the secondary MediaPackage origin at the same time. CloudFront receives the media quality score in the response headers from each origin.

1. Next, CloudFront tracks the score for each origin and uses this information to determine the origin with the higher score when a new request arrives.

The media quality score for your origins can change in real time. CloudFront determines this by consuming the MQCS changes, and switches between origins to ensure that viewers see the higher media quality content. For more information, see [Leveraging media quality scores with MediaPackage](https://docs.aws.amazon.com/mediapackage/latest/userguide/mqcs.html) in the *AWS Elemental MediaPackage V2 User Guide*.

MQAR helps CloudFront determine, as early as possible, whether there’s an issue that could potentially impact customers. For example, issues such as network connection, video processing, audio loss or drops, encoder speed problems can affect the media quality score for your viewers.

MQAR provides seamless switching between origins, so that you can deploy a resilient, cross-Region end-to-end media delivery workflow on AWS, and provide quality content for your viewers. 

**Note**  
Currently, this feature only supports MediaPackage v2 origins. 

To enable this feature for your distribution, complete the following steps:

1. If you haven't already, create your MediaPackage v2 origins and enable this feature in your endpoint configuration. For a cross-region deployment, create a secondary channel in a different AWS Region with the same settings. For more information, see the following topics in the see the *AWS Elemental MediaPackage V2 User Guide*:
   + [ Create a channel and endpoint](https://docs.aws.amazon.com/mediapackage/latest/userguide/getting-started.html)
   + [Enable the media quality score](https://docs.aws.amazon.com/mediapackage/latest/userguide/mqcs.html)

1. To use your MediaPackage v2 origins for CloudFront, create or update a CloudFront distribution. See [Create a distribution](distribution-web-creating-console.md) and [Update a distribution](HowToUpdateDistribution.md).

1. Create an origin group, and select your two origins as the primary and secondary. In your origin group, enable the **Media quality score** option. For more information, see [Create an origin group](high_availability_origin_failover.md#concept_origin_groups.creating).

1. In your cache behavior for your distribution, select the [origin group ](DownloadDistValuesCacheBehavior.md#DownloadDistValuesTargetOriginId) that you created. We recommend that the cache behavior match the channel path pattern.

If CloudFront determines that both MediaPackage v2 origins have the same score, then it forwards the request to the primary origin as listed in the origin group. If the initially selected origin responds with an error code matching the failover criteria you specified in your origin group, then CloudFront retries the request to the alternative origin in your origin group regardless of its media quality score.

**Notes**  
CloudFront tracks the quality score for each cache behavior that utilizes an origin group enabled for media quality score. If the same origin group is used for multiple channels that emit a media quality score, create a separate cache behavior for each channel's path pattern to avoid mixing their scores. For more information about origin group quotas, see [General quotas on distributions](cloudfront-limits.md#limits-web-distributions).
Currently, MQAR isn't available when you use a [Lambda@Edge](lambda-at-the-edge.md) function in origin-facing triggers (origin request and origin response) that is associated with your distribution's cache behavior. For more information, see [Cache behavior settings](DownloadDistValuesCacheBehavior.md).
If you enabled the MQAR feature and origin access control (OAC), add the `mediapackagev2:GetHeadObject` action to the IAM policy. MQAR requires this permission to send `HEAD` requests to the MediaPackage v2 origin. For more information about OAC, see [Restrict access to an AWS Elemental MediaPackage v2 origin](private-content-restricting-access-to-mediapackage.md).

## MQAR log fields
<a name="media-quality-score-log-fields"></a>

CloudFront provides the following fields in real-time access logs to reflect the quality score and the selected origin. You can enable these fields in your CloudFront real-time access logs logs:
+ `r-host`
+ `sr-reason`
+ `x-edge-mqcs`

For more information, see [Fields](real-time-logs.md#real-time-logs-fields) 65-67.