This is the step-by-step configuration guide for the ad insertion workflow discussed in Part 1: How to optimize ad delivery with AWS Elemental MediaTailor. The instructions show HLS-based examples, but AWS Elemental MediaTailor—a channel assembly and personalized ad insertion service—supports both HLS- and DASH-based workflows. In this guide you will:

  • Create a basic MediaTailor configuration and define:
    • Video content source
    • ad decision server (ADS) URL
  • Create an Amazon CloudFront, a content delivery network (CDN) service, distribution and define:
    • CDN origin and behavior for MediaTailor manifests
    • CDN origin and behavior for MediaTailor transcoded ad segments
    • CDN origin and behavior for your content origin, live or video on demand (VOD)
  • Finalize the MediaTailor configuration to add:
    • content segment prefix with the new Amazon CloudFront distribution domain.
    • ad segment prefix with the new Amazon CloudFront distribution domain
  • Play the over-the-top (OTT) stream using the Amazon CloudFront CDN URL for MediaTailor

Prerequisites

  • AWS Management Console, which is everything you need to access and manage the Amazon Web Services (AWS) cloud: login credentials to AWS Management Console.
  • AWS Identity and Access Management (AWS IAM), which provides fine-grained access control across all of AWS: If your AWS IAM user has the administrator access(AWS managed) policy, you can delegate permissions to every service and resource in AWS, including implementing all the steps in this guide. To create users with minimum required permissions necessary for this step-by-step guide, follow the instructions in the links below:
  • OTT content published to a web origin—for example, AWS Elemental MediaPackage, which reliably prepares and protects your video for delivery over the internet—in either HLS or DASH format. SCTE 35 signalingshould be present in the media manifest. SCTE 35 is the signaling standard for compressed video streams and is used extensively in ad insertion workloads. Alternatively for VOD content, your ADS should be set up to return a video multiple ad playlist (VMAP) response when MediaTailor issues a video ad serving template (VAST) request on client playback of VOD.
  • a CDN service. Instructions in this post use Amazon CloudFront.
  • a terminal to test retrieval of content manifests via public URLs. Instructions in this post use Mac Terminal and cURL commands.

Create MediaTailor configuration

  1. Log in to the AWS Management Console, and navigate to MediaTailor service using the search bar or by browsing through the AWS services catalog.
  2. Under ad insertion, click create configuration. On the new configuration page, under required settings, complete the following required fields to deploy the configuration:
    1. name: vod-ssai (or any other logical name to easily identify its purpose)
    2. video content source: this is the origin domain name of video content, including protocol (http:// or https://). An example of MediaPackage origin domain is egress.mediapackage-vod.us-west-2.amazonaws.com
    3. ad decision server: put the ADS URL here, including session and client player parameters. For more information on parameters, please review https://docs.aws.amazon.com/mediatailor/latest/ug/getting-started-ad-insertion.html#getting-started-configure-request and https://docs.aws.amazon.com/mediatailor/latest/ug/variables.html.

If an ADS server is not available, a reference ADS server available at https://github.com/scunning1987/ads_reference_server can be used for testing purposes to complete these step-by-step instructions.

  1. Click the create configuration button to complete the configuration.

Document the MediaTailor HLS playback prefix domain name for use in the CDN configuration.

Screen capture of a MediaTailor configuration overview with the HLS playback prefix highlighted

Create a CloudFront distribution

  1. Navigate to the Amazon CloudFront service console using the search bar or by browsing through the AWS services catalog.
  2. Under distributions, click create distribution.
  3. In the origin settings, the specified origin domain will become the default route for objects that do not match any other path pattern. The origin domain that serves the ad segments will be added as the default origin for this distribution. Additional origin domains and path patterns for routing client manifests and content segment requests will be added in subsequent steps.
    1. origin domainmediatailor.{region}.amazonaws.com where {region} should be replaced by the region that the MediaTailor configuration is deployed in—for example, us-west-2 region.
      1. protocol: select HTTPS only.
      2. Leave HTTPS portand SSL protocol to defaults for test setup, but change it based on specific requirements.
    2. origin path: leave this blank.
    3. name: MediaTailor-Ad-Segments (or any other logical name to easily identify its purpose)
    4. enable origin shield: leave it as no.
    5. additional settings: leave all settings to default values.
  4. In the default cache behavior settings, leave all settings to the default values, except for:
    1. viewer protocol policy: set it to HTTPS only.
  5. In the function associations settings, leave all settings to default value of no association.
  6. In the final settings, select the price class option, considering costs and location of users. Select the most cost-efficient price class for testing purposes.
  7. Click create distribution to complete the basic Amazon CloudFront distribution.

The distribution can take up to 15 minutes to deploy fully, but we can begin adding additional origins and behaviors while the distribution is deploying.

Create origins

  1. In the Amazon CloudFront service console, select the Amazon CloudFront distribution created in the previous section.
  2. There are two more origins that need to be created. One is for serving requests for content segments, and the other is for serving requests for personalized client manifest requests from MediaTailor.
  3. Click the origins tab, and then click create origin to set up the origin for serving content segments:
    1. origin domain: enter the domain name of the content origin without the protocol—for example, my-company-origin.com or 3ae97e9482b0xxxx.mediapackage.us-west-2.amazonaws.com
      1. protocol: select the protocol option supported by the content origin. For MediaPackage, select HTTPS only.
      2. Leave HTTPS port and SSL protocol to defaults for test setup, but change it based on specific requirements.
    2. origin path: leave this blank, or enter a path that will be added to the root path that Amazon CloudFront will use for requests to the content origin. More information can be found here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesOriginPath
    3. name: content-origin (or any other logical name to easily identify its purpose)
    4. Click create origin to complete adding the new origin to the distribution.
  4. Going back to the origins tab, select create origin to add the origin for serving personalized client manifests from MediaTailor:
    1. origin domain: enter only the domain name portion of the MediaTailor playback prefix that was documented previously on the creation of the MediaTailor configuration. For example, 8cfb050af7894d8d8a136473f0d59xxx.mediatailor.us-west-2.amazonaws.com.
      1. protocol: select HTTPS only.
      2. Leave HTTPS port and SSL protocol at default values for the test setup, or change them to meet specific requirements.
    2. origin path: leave this blank.
    3. name: MediaTailor-Manifests (or any other logical name to easily identify its purpose)
    4. Click create origin to complete adding the new origin to the distribution.

The Origin list should show three origins similar to the example snapshot below:

Screen capture of an Amazon CloudFront distribution’s origins list

Create CDN behaviors (origin routing)

The final steps in setting up the distribution requires configuring the CDN behaviors (also known as path-based routing rules).

  1. In the Amazon CloudFront service console, select the Amazon CloudFront distribution created in the previous section.
  2. Click on the behaviors A default behavior is listed that was created with the Amazon CloudFront distribution. This cache behavior will route all requests to the default origin if the requests path doesn’t match path patterns specified in any other behaviors within the distribution. To provide proper routing of all stream requests, two more cache behaviors will be added to this distribution:
    1. a cache behavior to match the path pattern-of-content segment requests and route them to the content origin.
    2. a cache behavior to match path pattern-of-personalized manifest requests and route them to the MediaTailor service.
  3. Click create behavior to set up the path pattern behavior for the content origin. In the settings section, configure the following:
    1. path pattern: identify the URL path pattern that uniquely identifies requests for content segments. For example, in a MediaPackage origin endpoint URL, the unique path pattern is “/out/” and the respective path pattern would be “/out/*”. For example, https://8343f7014c0exxxx.mediapackage.us-west-2.amazonaws.com/out/v1/e31918b886ec482f830178c53760xxxx/index.m3u8.
    2. origin and origin groups: select the origin name of the content origin from the drop-down menu.
    3. compress objects automatically: leave it as yes.
    4. In the viewer section, configure the following:
      1. viewer protocol policy: select HTTPS only, if using MediaPackage, or select the best option based on the content origin restrictions.
      2. Leave all other settings at default values, or change them based on specific requirements.
    5. In cache key and origin requests, select cache policy and origin request policy and configure the following:
      1. cache policy: select caching optimized from the drop-down menu to facilitate caching for the most efficient delivery of content segments from the Amazon CloudFront distribution.
      2. Leave all other settings at default, or change them based on workload-specific requirements.
    6. In the function associations section, leave all values at default.
    7. Click create behavior to complete the creation of the behavior.
  4. Going back to the behaviors tab, click create behavior to create the MediaTailor personalized manifest behavior:
    1. path pattern: for MediaTailor endpoints, the URL path pattern that uniquely identifies requests for MediaTailor client manifests is “/v1/”. The recommended path pattern for MediaTailor endpoints is “/v1/*”.
    2. origin and origin groups: select the origin name of the MediaTailor origin from the drop-down menu.
    3. compress objects automatically: leave it as yes.
    4. In the viewer section, configure the following:
      1. viewer protocol policy: select HTTPS only.
      2. Leave all other settings at default, or change them based on workload-specific requirements.
    5. In cache key and origin requests, select cache policy and origin request policy, and configure the following:
      1. cache policy: select caching disabled from the drop-down menu to deactivate caching of manifests. This is to help clients get a unique, personalized manifest from MediaTailor on every request.
      2. origin request policy: select Elemental MediaTailor–personalized manifests from the drop-down menu to use the specially designed policy that helps all query strings in the client manifests requests get passed to MediaTailor.
  • Leave all other settings at default, or change them based on workload-specific requirements.
  1. Click create behavior to complete the creation of the behavior.

The behaviors list should show three behaviors similar to the example snapshot below:

Screen capture of an Amazon CloudFront distribution’s behaviors list

NOTE: In this step-by-step guide, no path pattern definition was needed for the MediaTailor ad segment requests because they are routed by the default behavior without needing a pattern match. However, if your CDN setup requires the path pattern definition for routing the ad segments, you can use “/tm/*” as the MediaTailor ad segment URL path pattern. An example URL of an ad segment: https://segments.mediatailor.us-west-2.amazonaws.com/tm/61567c73cxxxxx997f20cf2b6/hq3xxxohjmp/asset_480_2.ts

Navigate to the general tab of the Amazon CloudFront distribution and copy the distribution domain name to your clipboard for finalizing the MediaTailor configuration.

So far the following resources have been created:

  1. A MediaTailor configuration pointing directly to a content origin and an ADS. The configuration will deliver client manifests pointing to the content origin for content segments and MediaTailor for ad segment URLs.
  2. An Amazon CloudFront distribution with origins and behaviors to appropriately route the following requests:
    • client manifest requests to the MediaTailor endpoint
    • content segment requests to the content origin
    • ad segment requests to the MediaTailor ad segment origin

Finalize MediaTailor configuration

In the final steps, the MediaTailor configuration will be updated to add the Amazon CloudFront distribution domain to the content segment prefix and ad segment prefix fields. With this update, when serving client media manifests, MediaTailor will replace the domain in the ad segment and content segment URL with the Amazon CloudFront domain. This will help all content and ad segments, along with the personalized client manifests, get served from the Amazon CloudFront distribution. It will also facilitate appropriate routing of the requests based on the behaviors and caching policies.

  1. Navigate to the MediaTailor service console, and click on the configuration name previously created.
  2. Click the edit button, and navigate to the advanced settings
  3. Populate the content segment prefix and ad segment prefix fields with your CDN distribution domain name. An example Amazon CloudFront domain URL: https://d2tfjdy83kvln.cloudfront.net/
  4. Click save configuration to complete the configuration update.

The setup is now complete and ready for testing.

Constructing the playback URL using the CDN

To test playback, build the content playback URL by combining the following:

```
Playback URL : https:// + [CDN distribution domain name] + [MediaTailor playback prefix path] + [Content path on the origin]
```
  1. CDN distribution domain name: get the Amazon CloudFront distribution domain from the distribution you created. An example domain: cloudfront.net
  2. MediaTailor (HLS) playback prefix: get the MediaTailor HLS playback prefix from the MediaTailor configurations. An example URL: https://8cfb050af7894d8d8a136473f0d59xxx.mediatailor.us-west-2.amazonaws.com/v1/master/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/. Copy the part of the prefix beyond the MediaTailor domain as shown for the example URL: /v1/master/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai
  3. content path on the origin: this is the path without the origin domain. An example content origin URL for MediaPackage: https://f337a469f5f293208fc7568453363xxx.egress.mediapackage-vod.us-west-2.amazonaws.com/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/cc1ea9871c934645a78d4a94c8209204/6350137eb4914046a0b39090654axxxx/index.m3u8. Copy the path beyond the MediaPackage domain: /out/v1/f257d73ceda44a56b5aea674c8c5xxxx/ cc1ea9871c934645a78d4a94c8209204/6350137eb4914046a0b39090654axxxx/index.m3u8

Based on the example above, the final HLS playback URL should be similar to:

https://d2tfjdy83kxxx.cloudfront.net/v1/master/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/ cc1ea9871c934645a78d4a94c8209204/6350137eb4914046a0b39090654axxxx/index.m3u8

An excerpt of the personalized client main manifest is shown below. It was fetched using cURL and the HLS playback URL similar to the one presented above.

```
$ curl -s https://d2tfjdy83kxxx.cloudfront.net/v1/master/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/cc1ea9871c934645a78d4a94c8209204/6350137eb4914046a0b39090654axxxx/index.m3u8
#EXT-X-VERSION:3
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-STREAM-INF:CODECS="avc1.4D401F,mp4a.40.5",AVERAGE-BANDWIDTH=511613,RESOLUTION=480x270,FRAME-RATE=14.985,BANDWIDTH=585288
../../../../../../../../manifest/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0.m3u8
#EXT-X-STREAM-INF:CODECS="avc1.4D401F,mp4a.40.5",AVERAGE-BANDWIDTH=731613,RESOLUTION=640x360,FRAME-RATE=29.97,BANDWIDTH=849288
../../../../../../../../manifest/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/1.m3u8
#EXT-X-STREAM-INF:CODECS="avc1.640028,mp4a.40.5",AVERAGE-BANDWIDTH=7256485,RESOLUTION=1280x720,FRAME-RATE=29.97,BANDWIDTH=8665188
../../../../../../../../manifest/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/6.m3u8
#EXT-X-STREAM-INF:CODECS="avc1.640028,mp4a.40.2",AVERAGE-BANDWIDTH=9491711,RESOLUTION=1920x1080,FRAME-RATE=29.97,BANDWIDTH=11333366
../../../../../../../../manifest/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/7.m3u8
```

From the client main manifest response (above), pick a media manifest URL path to fetch the respective media manifest. The media manifest will show the content segments URLs and ad segment redirect URL path when an ad break is present similar to the example shown below.

```
$ curl -s "https://d2tfjdy83kxxx.cloudfront.net/v1/manifest/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0.m3u8"
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:8
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXTINF:6.006,
https://d2tfjdy83kxxx.cloudfront.net/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/cc1ea9871c934645a78d4a94c8209204/d8764860d2644db9bbe402794cb94da6/38604cd06e614459aea9757afcadba72/index_1_0.ts
#EXTINF:6.006,
https://d2tfjdy83kxxx.cloudfront.net/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/cc1ea9871c934645a78d4a94c8209204/d8764860d2644db9bbe402794cb94da6/38604cd06e614459aea9757afcadba72/index_1_1.ts
#EXT-X-DISCONTINUITY
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/12
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/13
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/14
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/15
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/16
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/17
#EXTINF:2.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/18
#EXTINF:1.0,
../../../../segment/94063eadf7d8c56e9e2edd84fdf897826a70xxxx/mediatailor-ssai/84ed5c11-58aa-433d-a065-72e685b2xxxx/0/19
#EXT-X-DISCONTINUITY
#EXTINF:6.006,
https://d2tfjdy83kxxx.cloudfront.net/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/cc1ea9871c934645a78d4a94c8209204/d8764860d2644db9bbe402794cb94da6/38604cd06e614459aea9757afcadba72/index_1_2.ts
#EXTINF:6.006,
https://d2tfjdy83kxxx.cloudfront.net/out/v1/f257d73ceda44a56b5aea674c8c5xxxx/cc1ea9871c934645a78d4a94c8209204/d8764860d2644db9bbe402794cb94da6/38604cd06e614459aea9757afcadba72/index_1_3.ts
```

As expected, the content segment URLs have the Amazon CloudFront domain as configured in the content segment prefix. The URL returned for the ad segment on the redirect URL request will also contain the configured Amazon CloudFront domain and can be verified by monitoring traffic on the player. This completes the step-by-step configuration walk-through for MediaTailor and Amazon CloudFront using content segment prefix and ad segment prefix.

https://aws.amazon.com/blogs/media/how-to-configure-advanced-features-in-aws-elemental-mediatailor/

https://aws.amazon.com/blogs/media/part-1-how-to-optimize-ad-delivery-with-aws-elemental-mediatailor/

Categories: Media