Live2VOD Workflow

April 6, 2023 ยท View on GitHub

Log

DateEntryVersionComment
06/04/2023created0.0.1initial release of the application

Disclaimer

The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. You should not use this AWS Content in your production accounts, or on production or other critical data. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running AWS Elemental Live Channels or using AWS Elemental MediaPackage.

Table of content

Solution overview

This sample solution provides a practical code example to harvest clips from a MediaPackage Channel to an S3 bucket and ingest them as a MediaPackage VOD asset all through a simple RestApi call.

Stack Descriptions

Stack NameDescription
MediaServicesRefArch-L2V-vodassets-stackS3 bucket - used by MediaPackage to store clips that are harvested.
MediaServicesRefArch-L2V-media-stackThe live workflow using MediaConnect, MediaLive & MediaPackage.
MediaServicesRefArch-L2V-harvestapi-stackRest API for a user to "submit" a job to MediaPackage. Information on how to invoke the API can be seen below.
MediaServicesRefArch-L2V-harvestcomplete-stackCatches EventBridge event from MediaPackage when a harvesting has occured and uses Lambda to ingest into MediaPackage as a VoD asset.

Use case

You may want to use the MediaPackage Harvest API to save clips from a game for a highlight reel, or a broadcast show to use later in advertisements for the show. For further information have a look at our documentation.

Architecture

Code Sample Architecture

For this sample, we have broken it down to be simpler and less resources deployed into your account.

Code Sample Architecture

Full Architecture

In the full architecture diagram below, there are a few improvements to be seen versus the code sample provided:

  1. The code sample only uses a single pipeline - for redudency, we recommend using a standard pipeline (across 2 AZ's)
  2. There is only 1 output stream going to an origin (for simplicity only) - we recommend building and deploying a full ABR ladder.

Full Sample Architecture

Prerequisite

For your ElementalLive encoder to push to the cloud you need to create an IAM User dedicated to each encoder you are using on-prem. Follow this documentation to create this User and policy.

CDK deployment

Visit our AWS cloud Development Kit for more information on CDK. Get hands-on with CDK running the CDK introduction workshop. For this project we will make use of Typescript version of CDK. We will create a Typescript app using CDK, this app will abstract all the CloudFormation stack and resource creation. More information on CDK best practice can be found on AWS website.

Requirements

  • Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
  • AWS CLI installed and configured
  • Git Installed
  • AWS Cloud Development Kit (AWS CDK >= 2.2.0) Installed
  • Language used: Typescript
  • Framework: AWS CDK

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/aws-cdk-mediaservices-refarch
  1. Change directory to the pattern directory:
cd LIVE2VOD
  1. Install node modules:
npm install
  1. Please ensure that you configure for your environment by overriding values in the config.ts file before deploying this solution.

  2. Build CDK App

npm run build
  1. Deploy Playout Stack
npm run cdk deploy MediaServicesRefArch-L2V-vodassets-stack
  1. Deploy Media Stack
npm run cdk deploy MediaServicesRefArch-L2V-media-stack
  1. Deploy Harvest API Stack
npm run cdk deploy MediaServicesRefArch-L2V-harvestapi-stack
  1. Deploy Harvest Complete Stack
npm run cdk deploy MediaServicesRefArch-L2V-harvestcomplete-stack

Running the solution

Once your system is deployed and configured correctly with the right downstream origin/system - you'll need to start the following:

  • MediaConnect flow
  • MediaLive channel

Testing

  1. Once you have defined your downstream system (i.e. an Origin solution) you will be able to see streams/data being received from MediaLive (upstream).

Harvesting Clips

Endpoint

Get the endpoint URL from Stack MediaServicesRefArch-L2V-harvestapi-stack outputs with the export name harvest-api-endpoint. It should appear like the following: https://<id>.execute-api.eu-west-1.amazonaws.com/prod/harvest

Once you have got your API endpoint, you need to assume a role to execute the API. This is in the outputs of same stack (MediaServicesRefArch-L2V-harvestapi-stack) called harvest-api-role.

To get credentials use the following CLI command:

aws sts assume-role --role-arn <insert-iam-role-arn> --role-session-name api

Once you have credentials, you can use a REST API client to make a request to the endpoint (using AWS credentials).

It is a HTTP POST to the API with the following parameters:

{
	"min":"<insert-start-epoch-timestamp>",
	"max":"<insert-end-epoch-timestamp>",
	"originId":"MediaServicesRefArch-L2V-EMP-hls-output"
}
Sample HTTP POST Body
{
	"min":"1675766280",
	"max":"1675766310",
	"originId":"MediaServicesRefArch-L2V-EMP-hls-output"
}

Cleanup

  1. Stop MediaLive channel

  2. Stop MediaConnect Flow

  3. Delete the stacks

Tutorial

See this useful workshop on working with the AWS CDK for typescript projects. More about AWS CDK v2 reference documentation here.

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

Best practice

  • Security: Content security is key to the success of a streaming platform. So make sure to make use of encryption at rest for your assets with the bucket encryption capabilities and secure the transport of your content with https or s3ssl protocols. Ensure you have authentication and authorization in place at a level commensurate with the sensitivity and regulatory requirements of your assets. Consider using MFA whenever possible to access your ressources. Where possible access logging should also be enabled and encrypted.
  • Reliability: For demos and debugging purpose this solution run a single pipeline to process your content. However, in a production environment make sure to remove any single point of failure by using the STANDARD mode which allows for dual pipeline creation to process your content in the cloud.
  • Operation: Enabling logs on the channel will give you more insight on what is happening in your infrastructure should you need to investigate any issue. You can enhance your CDK application with API calls to automate operational tasks based on triggers.
  • Cost: Review your encoding settings to optimize your ABR ladder. Consider reservation for 24/7 workflow. Make use of bandwidth optimized control rate such as QVBR to save bandwidth on CDN usage when possible.

License

This library is licensed under the MIT-0 License. See the LICENSE file.