11 Oct 2015 | Azure | CDN | Azure Storage Accounts
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.
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
.
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";
client.SetServiceProperties(properties);
Console.WriteLine(properties.DefaultServiceVersion);
Setting up the CDN itself it pretty straight forward:
New > CDN > Quick Create
. Select your subscription and set the origin type as Storage Account
.
Select one of the classic storage accounts from the Origin Url
drop down and hit the create button.
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.