Networking & Content Delivery

Simple Serverless Video On Demand (VOD) Workflow

This post discusses the basics of setting up a simple serverless video on demand (VOD) workflow so you can experiment with streaming video with minimal configurations required. (If you have a more advanced VOD use case, check out this post and CloudFormation template from AWS Answers.) To setup a serveless video transcoding workflow, you first create an Amazon S3 bucket and associate it with a Lambda trigger that submits a transcoding job using Amazon Elemental MediaConvert when a new file is ingested. The transcoding job specifies video packaging settings like HLS and DASH along with the bitrates that are expected from the transcoded output. This information is all stored in another Amazon S3 bucket. Finally, the videos are delivered securely by Amazon CloudFront, restricting access to the Amazon S3 bucket by using origin access identity (OAI).

In this deployment template, we’ve simplified this setup process so you only need to specify a few items, including the input watch folder, the destination folder to hold your transcoded files, and your packaging needs. After you provide the initial information, the template sets up the entire workflow for you, using typical bitrates—and you’re done!


Launch the CloudFormation template

Using this template as a starting point, it’s also easy to build customized workflows.

1) Choose your parameters

Click Next, and then choose options on the Parameters page. When you deploy the template, you specify the following parameters:

  • StackName – Enter a name for the deployment stack. All the resources that are created will have this name as a prefix.
  • BucketName – Enter the bucket prefix to use in the bucket name, which has the following format:{bucket-name}-AWSAccountId-AWSRegion.

For example: if you specify a bucket name as ‘test’ and deploy it in the us-east-1 Region from AWS Account Id ‘123456789012’, then the full bucket name would be: test-123456789012-us-east-1. Having a unique bucket name allows you to deploy multiple stacks in the same or different AWS Regions.

  • EmailAddress – Enter the email address to send notifications to after a video transcoding job is completed. You’ll need to confirm your subscription to the notifications by clicking the link that’s emailed to the address right after deployment.
  • InputPrefix – Enter the watch folder for the S3 event notifications Lambda trigger.
  • OutputPrefix – Enter the output folder for storing the transcoded files.
  • PackageType – Choose whether you need HLS or DASH or BOTH video packaging. Based on the options you choose, custom job presets with following resolutions and bitrates are created and used for video transcoding.
Package Type Resolution (width x height) Bitrate (Mbps)
HLS & DASH 480 x 270 0.4
HLS & DASH 640 x 360 0.6
HLS & DASH 640 x 360 1.2
HLS & DASH 960 x 540 3.5
HLS & DASH 1280 x 720 5
HLS & DASH 1920 x 1080 8.5

2) Move through the setup

Click Next, then Next again. When you’re prompted to acknowledge that you’re creating IAM resources with custom names, click Yes. Next, click Create Change Set, at the bottom of the page. Finally, click Execute to launch the CloudFormation stack. It may take several minutes to complete. In the meantime, check your email and click the link to confirm your subscription to the new SNS topic.

The stack creates the following:

  • An Amazon S3 bucket with Server Side Encryption (SSE) and appropriate Cross Origin Resource Sharing (CORS) and Origin Access Identity (OAI) settings for private content access from CloudFront.
  • A Lambda function that’s triggered whenever a video is uploaded to a specified input/watch folder, defined by the InputPrefix parameter that you specified earlier. The Lambda function constructs a specific transcoding MediaConvert job to package the video output based on the PackageType option you selected.
  • An Amazon CloudFront distribution set up with the Amazon S3 bucket as the origin, accessed with OAI.

3) Create the input and output folders

Select the new CloudFormation Stack, and, on the Outputs tab at the bottom of the page, make note of the new BucketName. In the AWS Management console, open the S3 console, and then select the new bucket that you just created. In the bucket, create a folder using the inputPrefix name that you specified earlier. If you didn’t change the default inputPrefix, name the folder in your S3 bucket input. Optionally, repeat the steps to create an Output folder. If you didn’t change the name of the output folder for the OutputPrefix parameter earlier, name the folder output.

4) Upload a video

Now upload a video that you’d like to transcode into the input folder. Note: the name of the video must have only letters and numbers. File names with spaces are not accepted because they’ll cause an error when AWS Elemental MediaConvert begins transcoding. Transcoding begins as soon as you upload the file. When it’s complete, or if there’s a processing error, you’ll receive an email notification

5) Construct the final URLs for accessing the videos

To access the transcoded videos, you use URLs composed of the output files and the endpoint URLs for each output type. After AWS Elemental MediaConvert transcodes your video, it saves the assets to a folder in the S3 bucket named by your OutputPrefix parameter. To construct the final URL, you’ll concatenate the output file name with the CloudFront URL in the Outputs tab of the CloudFormation Template you launched. You’ll have one URL for HLS output and a different URL for DASH output. See the following steps and screenshots to help you locate and copy the file names and URLs.

  • Copy the output file name from your S3 bucket. To locate the file name, in the Outputs folder that you created, select either the HLS or DASH folder. Then, select the file and copy the file name. For example, for the following output, you would copy testvid.m3u8:

  • Locate the DASHEndpoint and HLSEndpoint URLs by going to the CloudFormation Stack that you just created. The HLSEndpoint and DASHEndpointSelect URLs are displayed on the Outputs tab at the bottom of the page, as shown in the following screenshot:

  • To create the final URLs that you can use to access the videos, append the output file name to the HLSEndpoint and DASHEndpoint URLs.

In this example, we uploaded a file named testvid.MOV to the input folder: input/testvid.MOV. So the CloudFront URLs we’ll use to access HLS and DASH videos are the following:

  • HLS – https://dxxxxxxx.cloudfront.net/output/hls/testvid.m3u8, where the assets are located in /output/hls/testvid/
  • DASH – https://dxxxxxxx .cloudfront.net/output/dash/testvid.mpd, where the assets are located in /output/dash/testvid/

6) Test with a player

You can try playing the videos by using the JWPlayer stream tester tool: https://developer.jwplayer.com/tools/stream-tester/

Open the JWPlayer stream tester tool, and then copy and paste one of the URLs that you created into the tool.

7) Use Online Video Player of your choice

Finally, now that you’ve confirmed that the videos stream correctly using CloudFront, you can use your new URL endpoints in the player of your choice to start streaming your videos on demand.

Blog: Using AWS Client VPN to securely access AWS and on-premises resources
Learn about AWS VPN services
Watch re:Invent 2019: Connectivity to AWS and hybrid AWS network architectures