Day 91: Azure Cloud Service with Web Role and Worker Role for IT Pros (Part 3)

Welcome to Day 91 of the “100 Days of DevOps with PowerShell”! For background on our goals in this series, see Announcing the “100 Days of DevOps with PowerShell” Series here at SCC. If this is the first time you are viewing an article of the series and you are new to DevOps and PowerShell Desired State Configuration (DSC), I encourage you to read through the previous installments, particularly Day 1.


This article assumes the following are true:


In this post, which is the third of four parts in this series-within-a-series, we will look at Azure Cloud Services, using a sample application called Contoso Ads. We have been a light on some of the details of the Azure Cloud Service package to this point, so we will talk about what comprises a package, then build a package, deploy the prerequisites for the application, then deploy that package with PowerShell.

Package Requirements for Deployment to Azure

To run an application as a cloud service in Windows Azure, you must package the application files into a package file (.cspkg) and then upload the package file and the service configuration file to Windows Azure. To package an application, you can use the CSPack command line utility or Visual Studio. The package consists of two files:

  • Azure Cloud Service Package (.cspkg) – An application package, which is used to run the application as a cloud service, includes the application files and the service model files. Once the package file is created, you can upload the package file and the service configuration file to Azure. Read more at
  • Azure Cloud Service Configuration Schema (.cscfg) – The service configuration file specifies the number of role instances to deploy for each role in the service, the values of any configuration settings, and the thumbprints for any certificates associated with a role. If the service is part of a Virtual Network, configuration information for the network must be provided in the service configuration file, as well as in the virtual networking configuration file. Read more at

Build the Package

Launch Visual Studio and browse to the Contoso Ads Cloud Service solution file we began working with on Day 86. From the View menu, select Solution Explorer. image On the next screen, enable Remote Desktop for the Web and Worker roles if wish. SNAGHTMLab2997b If you choose to enable remote desktop, you will need to supply a user name and password for an account with local administrator rights. Click OK when you’re done to return to the Package Azure Application screen. SNAGHTMLab34849 Click Package to create the cloud service package. You will see some logging in the Output pane at the bottom of your Visual Studio window. image When the build is complete, a window will open automatically with the two files described earlier in this article. image

Deploy Cloud Service Package Prerequisites via PowerShell

This step assumes the Azure cloud service, storage account, Azure SQL Server and ContosoAds database before deploying the Contoso Ads sample app from Visual Studio as we did yesterday in Day 90. However, If you wanted to automate provisioning of the Azure cloud service (and associated certificate), as well as the Azure SQL Server and ContosoAds database, that very possible (and relatively easy) in PowerShell.

Cloud Service and Certificate

To create the cloud service in the right datacenter and upload the SSL certificate, assuming you opt for HTTPS for production-readiness as I did in building the Azure cloud service package above, only takes a couple of lines of PowerShell, as shown here:


Azure SQL Server and Database

I am not going to rehash how to automate this task, as there are two installments in this series that show you the way. Go back to Day 61 – Provisioning an Azure SQL Server Instance via PowerShell (Oct 24) Day 66 – Provisioning an Azure SQL Database Instance via PowerShell (Oct 31) These two previous installments will show you all you need to know.

Deploying the Cloud Service Package

Microsoft has posted a sample script to demonstrate deployment of an Azure cloud service (available HERE), though, I had to make a couple of changes to get it to work, including sorting through some errors related to the missing SSL certificate on the cloud service. I have posted my slightly modified version here. You will notice some of the parameters have default values that you can override when you call the script. Also, watch for failure of import-module, as the path to the Azure PowerShell module may be different than the sample in your environment, as it was in mine.

Sample Azure Cloud Service Script

The modified sample script is shown here. Save as PublishCloudService.ps1 to your admin workstation.

As a general practice, edit the script in the PowerShell ISE, but call the script (as shown below) from an elevated PowerShell prompt.

Calling the Sample Script

Calling the sample script to deploy a cloud service is shown here. Be sure to replace my values with the correct values for your environment, and run from an elevated PowerShell command prompt. This is actually a single line script, but I broke it up into multiple lines for display purposes.

A successful deployment generates the following output: image And you are done. You can also change the environment from Production to Staging to deploy an instance of the sample app into each deployment slot. NOTE: At the bottom of this screen, there is a button labeled SWAP that switches the Staging environment to Production and vice versa. This enables quick and easy rollback in the event the new code release is not working as expected. image


That’s it for the third installment of this four part mini-series on Azure cloud services, Web and Roles.Now you have deployed an Azure cloud service through both Visual Studio 2013 and PowerShell. In the fourth installment (Day 95), we will take a look at lifecycle management of Azure cloud services with PowerShell.

Previous Installments

To see the previous installments in this series, visit “100 Days of DevOps with PowerShell”.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.