Wednesday, October 27, 2021

New Deployment Based On Existing Classic Cloud Service



For some scenarios, customer application source code / package are not available any more for some reason, but another deployment is needed. This is customer responsibility to manage application source code and apply new deployment, but customer cannot apply new deployment without source code. For such situation, we could try below approach as additional help. This blog will wrap up all information needed for you to get the deployment package of an existing cloud service(classic) and then use the deployment package for another Cloud Service(classic) deployment. 



  • Step One: Generate a Management Certificate. 
  • Step Two: create a classic storage account. 
  • Step Three: Use the Invoke-RestMethod PowerShell command to call the Get Package API. 



Step One: Generate a Management Certificate. 



First of all, we need to have a Management Certificate of our Cloud Service(classic), as the thumbprint of the Management Certificate will be used to call the rest API. 

Usually, Management Certificate allows specific users who authenticates with them to manage the subscription they are associated with, by calling the management API. It’s a different cert with the service certificateYou can check this document for details about the certificates: 


1. Navigate to the subscription and check your management certificate. 




2. (Optional) Please notice that you would have to be a Co-administrator on the subscription to perform any operations under Management Certificates. You can check your permission here: 





If you don’t have the permission to browse or upload the management certs, you can contact your subscription admin and then be added as a co-admin of the subscription. 


3. Generate a self-signed certificate using PowerShell:  


Once you’ve generated the self-signed cert, please make sure you’ve exported the file as a .cert format. Also please make sure that you’ve installed the cert on your local machine. 

My example down below: 



 4. Upload the cert to your management certificate: 



Once you’ve upload the certificate, you would be able to find it in the management certificates list and you can copy the thumbprint to use in the following steps. 



Step Two: create a classic storage account. 


Secondly, we need to have a classic storage account to store the generated package files. Please also make sure that the classic storage account is in the same subscription with your Cloud Service(classic). 


1. Navigate to the storage account creation page, then under instance details, click the legacy storage account type. 



 2. At the page popup, under the instance details, choose classic deployment model. 



3. Now, you would be at the create classic storage account page, fill out the information and click on create. 




 4. Verify you’ve create a classic storage account as below: 




5. Go to the storage account and create a container, then copy the container URL: 




Step Three: Use the Invoke-RestMethod PowerShell command to call the Get Package API. 


The Get Package operation would retrieve a cloud service package for a deployment and stores the package files in Microsoft Azure Blob storage. 

The following package files would be put into storage: 

  • Service configuration file - The cloud service configuration file (.cscfg) provides configuration settings for the cloud service and individual roles, including the number of role instances. 
  • Service package - The service package (.cspkg) contains the application code and the service definition file. 


Usually, the Get Package request is in the below formats: 




1. In PowerShell, run the script to retrieve the package: 

$URI="<subscription-id>/services/hostedservices/<cloudservice-name>/deploymentslots/production/package?containerUri= <StoragecontainerURL>" 

$method = "POST"  

$headers = [ordered]@{ "x-ms-version" = "2012-03-01"; "ContentLength" = "0" }  


Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -CertificateThumbprint $cerThumbprint 


Please note that Storage Container URI would be path till your container of your storage account where your package and configuration file will be uploaded. In this case, we have just copied from step two.  ex- 




2. Then, navigate to the container, and you would see the package and files. 



 3. use the deployment package(.cscfg and .cspkg) to make another deployment. 

You can also download the .cscfg file and modify it for your needs. In my case, I made a change of the instance counts from 1 to 3 instances. Then created another cloud service(classic) use the package file and .cscfg file. 






Posted at