Fri, 06 Nov 2009

Using the New Windows Azure CDN with a Custom Domain

Today we announced a new service in Windows Azure: the Windows Azure Content Delivery Network (CDN).  You can read about the details over on the Windows Azure blog.  In short, you can now tap into our global CDN to cache your content close to your users.  The Windows Azure CDN is a free preview for now, and we’ll announce pricing information in the future.

As we all know, my blog is an international sensation, and I sometimes include images in my posts.  Now I have the opportunity to boost the performance of my blog by serving those images from the Windows Azure CDN.  In this post, I’ll show you how I enabled the CDN under a custom domain name for images on my blog.

Step 1: Enable the CDN

step 1 - enabling cdn As of today, there’s a new section in the Windows Azure portal when you view one of your storage accounts.  Click the “Enable CDN” button to turn on the CDN.  Note that even though you get immediate confirmation that the CDN is enabled, it may take quite some time (expect 60 minutes) for the change to propagate throughout the network.

Once you’ve completed this step, you should see something like the following, which tells you the URL at which your blobs are now available via the CDN.  Note that only blobs in a public container will be cached and served by the CDNstep 1b - cdn enabled

That’s all you have to do to get the CDN functionality, but as you’ll notice, the URL for the CDN is a bit ugly.  In the next step, we’ll get a cleaner URL by mapping a custom domain.

Step 2: Map a Custom Domain

Along with the Windows Azure CDN, today we’ve introduced functionality to map custom domains to either CDN URLs or storage accounts directly.  I don’t want the image URLs on my blog to have the domain az2386.vo.msecnd.net in them, so let’s map the custom domain cdn.blog.smarx.com and use that instead.

Below the CDN section in the portal, you should see another new section called “Custom Domains.”  It shows your normal blob endpoint as well as your CDN endpoint.step 2 - domain mappings When you click the “Manage” button, you get to choose the domain you’re going to map (via a CNAME record) to the endpoint.  In my case, I chose cdn.blog.smarx.com.step 2b - choosing a subdomain Before the CDN will start serving requests from this custom domain, you need to prove that you actually own it.  When you click the “Generate Key,” you’ll get instructions for what to change in your DNS settings to validate your ownership of the domain.

step 2c - validating domain ownership Follow the instructions to prove ownership of the domain.  If you’ve never set up a CNAME record before, you might want to read my previous blog post about using custom domains in Windows Azure, which includes a screenshot of what it looks like to do this with GoDaddy.

After mapping the GUID subdomain to domainnameverification.windows.azure.com, you can click the “Validate” button.  Assuming your CNAME record was properly set up, you should be taken back to the storage account page.

Now you’ll see that your custom domain is mapped to the CDN.step 2d - success To finish the process, go back to your registrar and set up the real CNAME record (in my case, cdn.blog mapping to az2386.vo.msecnd.net).  Now you should be able to use your custom domain name and the domain provided by the CDN interchangeably.

You can follow the same mapping and validation steps to use a custom domain to point directly to your blob storage endpoint.

Success (and proof)!

I did all the above steps, and now the blobs I use for my blog are available under:

  • http://smarxblog.blob.core.windows.net/
  • http://az2416.vo.msecnd.net/
  • http://cdn.blog.smarx.com/

As proof, check out the properties of any of the screenshots in this post.  They’re being served from the CDN, and if you click them, you can browse directly to a higher-resolution version.