Set up basic CloudFront integration with MediaTailor - AWS Elemental MediaTailor

Set up basic CloudFront integration with MediaTailor

AWS Elemental MediaTailor integration with Amazon CloudFront improves content delivery performance for your viewers. This topic guides you through setting up a basic CloudFront distribution for MediaTailor. With this integration, your viewers can access personalized content through the CloudFront network. You'll also learn how to configure proper caching for different content types.

Prerequisites

Before configuring CloudFront with MediaTailor, ensure you have the following:

  • An active AWS account with permissions to create and manage CloudFront distributions

  • A configured MediaTailor playback configuration (see Using AWS Elemental MediaTailor to insert ads)

  • Your content origin server properly set up and accessible

  • Basic understanding of video streaming concepts (HLS/DASH)

Configuring CloudFront distribution

Follow these steps to create and configure a CloudFront distribution for MediaTailor:

To create a CloudFront distribution for MediaTailor
  1. Sign in to the AWS Management Console and open the CloudFront console at https://console.aws.amazon.com/cloudfront/v3/home.

  2. Choose Create Distribution.

  3. For Origin domain, enter your MediaTailor endpoint URL (for example, a1b2c3d4.mediatailor.us-west-2.amazonaws.com).

  4. For Protocol, select HTTPS only.

  5. For Name, enter a name that helps you identify this origin (for example, mediatailor-origin).

  6. Configure the default cache behavior settings:

    1. For Path pattern, use the default value (*).

    2. For Compress objects automatically, select Yes.

    3. For Viewer protocol policy, select Redirect HTTP to HTTPS.

    4. For Allowed HTTP methods, select GET, HEAD.

    5. For Cache policy, select CachingDisabled.

    6. For Origin request policy, select AllViewer to ensure all required headers including Host are forwarded to MediaTailor.

      Note

      The AllViewer policy forwards all viewer headers including the Host header, which is required for MediaTailor to function correctly. For more information about Host header requirements, see Configure Host header forwarding.

  7. Configure the distribution settings:

    1. For Price class, select the option that best matches your audience locations.

    2. For AWS WAF web ACL, select an existing web ACL or leave as Do not enable security protections.

    3. For Default root object, leave empty.

    4. For Standard logging, select On to enable logging.

  8. Choose Create Distribution.

Configuring cache behaviors

After creating your distribution, you need to configure additional cache behaviors to handle different types of content appropriately. This section covers basic cache behavior setup for CloudFront.

For comprehensive caching optimization including advanced TTL settings, cache key configurations, and performance tuning, see Caching optimization for CDN and MediaTailor integrations in the CDN optimization guide.

Configuring manifest cache behavior

Do not cache manifests because they contain personalized content. Follow these steps to configure the cache behavior:

To configure manifest cache behavior
  1. In the CloudFront console, select your distribution.

  2. Choose the Behaviors tab.

  3. Choose Create behavior.

  4. For Path pattern, enter *.m3u8 to match HLS multivariant and media playlists.

  5. For Origin, select your MediaTailor origin.

  6. For Cache policy, select CachingDisabled.

  7. For Origin request policy, select AllViewer to ensure all required headers are forwarded.

  8. Choose Create.

  9. Repeat these steps for DASH manifests using the path pattern *.mpd to match MPDs.

This configuration ensures that each viewer receives a personalized manifest with their specific ad content. The CDN doesn't cache these manifests, so each request goes directly to MediaTailor.

Configuring segment cache behavior

Cache content and ad segments aggressively to improve performance and reduce origin load. Follow these steps:

To configure segment cache behavior
  1. In the CloudFront console, select your distribution.

  2. Choose the Behaviors tab.

  3. Choose Create behavior.

  4. For Path pattern, enter *.ts to match HLS segments.

  5. For Origin, select your MediaTailor origin.

  6. For Cache policy, select CachingOptimized.

  7. For Origin request policy, select AllViewer to ensure all required headers are forwarded.

  8. For ad segments (/tm/*), in Response headers policy, select the managed policy CORS-with-preflight-and-SecurityHeadersPolicy.

  9. Choose Create.

  10. Repeat these steps for other segment types using appropriate path patterns (for example, *.mp4, *.m4s, and /tm/*).

This configuration caches segments at edge locations. Caching reduces load on your origin and improves delivery speed for your viewers.

Updating MediaTailor configuration

After setting up your CloudFront distribution, update your MediaTailor configuration to use the CloudFront domain:

To update your MediaTailor configuration
  1. Open the MediaTailor console.

  2. Select the configuration you want to update.

  3. In the CDN configuration section, enter your CloudFront distribution domain name (for example, d1234abcdef.cloudfront.net) in the CDN content segment prefix field.

  4. Save your changes.

With this configuration, MediaTailor generates manifests with URLs that point to your CloudFront distribution instead of directly to the origin.

Testing your integration

After configuring your CloudFront distribution and updating your MediaTailor configuration, test the integration:

To test your CloudFront and MediaTailor integration
  1. Request a manifest through your CloudFront distribution (for example, https://d1234abcdef.cloudfront.net/v1/master/12345/my-config/index.m3u8).

  2. Verify that the manifest contains segment URLs that point to your CloudFront domain.

  3. Play the content through a video player and verify that both content and ads play correctly.

  4. Check CloudFront logs to ensure requests are being routed correctly.

Example configuration

Here's an example of a CloudFront behavior configuration for MediaTailor:

Example CloudFront behavior configuration example
{ "DefaultCacheBehavior": { "TargetOriginId": "mediatailor-origin", "ViewerProtocolPolicy": "redirect-to-https", "AllowedMethods": { "Quantity": 2, "Items": ["GET", "HEAD"] }, "ForwardedValues": { "QueryString": true, "Cookies": { "Forward": "all" }, "Headers": { "Quantity": 1, "Items": ["User-Agent"] } }, "MinTTL": 0, "DefaultTTL": 0, "MaxTTL": 0 } }

Next steps

After setting up your basic CloudFront integration with MediaTailor, consider these next steps: