Use CNAME to reach the staging slot in #Azure cloud services with a well known url

If you already used the VIP swap functionality in a cloud service, you quickly noticed that for the production slot you have a deterministic url in the format {cloudservicename}.cloudapp.net. For the staging slot, that is something totally different.

The problem: random generated name

You end up with a {auto-generated-guid}.cloudapp.net which makes it hard to give something usable to dev or testers since it will change again and again when you recreate a deployment in the staging slot. Azure will not help you there, they don't offer a way to have a deterministic DNS entry for the staging slot at the time of writing this article.

A solution: Use a CNAME dns entry

To avoid that problem, you can use a CNAME entry that point to {auto-generated-guid}.cloudapp.net. That way you can give your users a well known url that will never change. You will need to update your CNAME entry when you perform a new deployment to your staging slot though but this can be automated.

param(
    [Parameter(Position=0,Mandatory=$true)]
    [string]
    $SubscriptionName,
    [Parameter(Position=1,Mandatory=$true)]
    [string]
    $ServiceName
)
$ErrorActionPreference = 'Stop'

Select-AzureSubscription -SubscriptionName $SubscriptionName
$service = Get-AzureService -ServiceName $ServiceName
$deployment = $service | Get-AzureDeployment -Slot Staging

'Staging Url is: {0}' -f $deployment.Url

From that sample script you have access to the staging url via $deployment.Url, you can then use that value to update you DNS server.

Get more information on deployments and how to manage cloud services