Search code examples
azureazure-web-rolesazure-worker-rolesazure-cloud-services

Get Cloud Service Name in a Web Role


We have a requirement of logging Cloud Service Name where Web Role is deployed.
We are getting Role Name & Role Instance Id from RoleEnvironment class in Azure ServiceRuntime library. But not finding Cloud Service Name.


Solution

  • You can't find this information via RoleEnvironment class. You would need to use Service Management API for that purpose. Basically the trick is to get the deployment id from RoleEnvironment class and then invoke Service Management API operations to

    • First list the cloud services in the subscription
    • Then iterate over each cloud service to get its deployment properties.
    • Find the one with matching deployment id.

    That would give you the information you need.

    To invoke Service Management API operations, you could use Azure Management Library or write your own REST wrapper. I did a blog post long ago where I did similar thing using REST API: http://gauravmantri.com/2012/03/16/programmatically-finding-deployment-slot-from-code-running-in-windows-azure/.