How to determine if an instance is in a Production or Staging deployment


  • I'm trying to find a way to tell if the current instance where my code is running is part of a deployment that is in a Production or Staging slot.

    The problem that I'm trying to solve is this: I have a timer object that runs every few minutes and triggers certain events. When I deploy a new package to Azure, I normally deploy in the Staging slot and after some validation I do a VIP Swap to promote that to Production.

    While the instances are in the Staging slot, I want to prevent them from triggering the events.

    After doing some research of the Service Management APIs, the only solution seems a bit awkward to me:

    1. Use Microsoft.WindowsAzure.ServiceRuntime to determine the Deployment Id for the current instance
    2. Add an entry to the Service Configuration to include the Subscription Id
    3. Add the Azure Management Certificate to the Hosted Service
    4. Use the Service Management RESTful APIs to query for all the hosted services and their production deployments
    5. Look for the Deployment Id from Step 1 with the list of Production Deployment Ids in Step 4.

    This should work, but I would prefer to avoid steps 2 and 3. Given that this instance is already running on Azure, it is clearly associated with a subscription that the code has been deployed by somebody who was authenticated with the management certificate.

    Since this package is going to be deployed in multiple hosted services and subscriptions, I'd prefer to minimize the deployment of management certificates and the configuration overhead.

    So, is this the only approach or are there any others that would simplify the deployment?


    Tuesday, March 13, 2012 3:09 PM


All replies

  • Use the Service Management RESTful APIs to query for all the hosted services and their production deployments

    I think list all hosted services management api can't query hosted services' deployment slot because of deployment ID is not in Response Body:

    So your method can not achieve goal, i think.

    Try to use this api, Get Deployment, you can check the deployment id with different hosted service name and deployment slot, but you may need to design a loop by your self.

    If you want list all service api can return deployment id in its response, try to post your idea as a feature request to Windows Azure Platform:

    Hope it can help you.

    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact Microsoft One Code Framework

    Wednesday, March 14, 2012 7:42 AM
  • Thanks Arwind... what you describe is exactly what I meant. I had to first query all the hosted services... then for each hosted service get its production slots.

    This would be a lot easier if there was a property in Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment that would tell me if the instance is in a production or staging slot.

    This may be hard since the deployment status is probably not available in the instance itself... so the next best thing would be to add the SubscriptionId and the ServiceName to the RoleEnvironment. That way at least I can just get the deployment status with just one call to the REST API.

    Wednesday, March 14, 2012 11:23 AM