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.
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:
Create a new CDN through the old portal by selecting 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.