Setting up a CDN to Stream Video via Azure Storage

I needed to setup an Azure Content Delivery Network (CDN) in order to stream some video files stored in Azure Blob Storage. Sounds simple enough right? Well, yes for the most part, but I did hit a few hurdles along the way. This post would hopefully help me avoid them the next time.

Create the Storage Account

Something I found out after the fact was that CDN endpoints currently only support classic storage accounts. So the first order of business is to create a classic storage account either via old portal or using a resource group manager template.

Another thing I found out is that, at the time of writing, classic storage accounts cannot be made under the 'East US' location. The closest alternative was 'East US 2' and worked fine; I guess its something worth considering if you wanted to co-locate all your resources.

Next, create a container within storage account - the container would host the files that would be served by the CDN. It can be created manually via the old portal or even through visual studio. Ensure that container access type is set to Public Blob.

Upgrade the Storage Account to a Newer Service Version

The first time I tried to tried to stream a video, it did not work as expected; stream was very choppy. It turns out that the service version that got set on the storage was not the latest. Read more here, and here.

So the next step is update the storage account to the latest version in order to take advantage of the improvements. This can be done using the following code:

    var credentials = new StorageCredentials("accountname", "accountkey");
    var account = new CloudStorageAccount(credentials, true);
    var client = account.CreateCloudBlobClient();
    var properties = client.GetServiceProperties();
    properties.DefaultServiceVersion = "2013-08-15";

Create the CDN Endpoint

Setting up the CDN itself it pretty straight forward:

  1. Create a new CDN through the old portal by selecting New > CDN > Quick Create.
  2. Select your subscription and set the origin type as Storage Account.

    Azure Create CDN

  3. Select one of the classic storage accounts from the Origin Url drop down and hit the create button.

    Azure CDN Created

Upload Content

Now that everything is setup, go ahead and upload the content into blob storage using Visual Studio or Azure Storage Explorer. Once the content is propagated, video streaming should be smooth and working as expected.


comments powered by Disqus