Introduction
Azure (Platform-as-a-Service) website provides limited control to developers to play with the underlying Virtual Machine File System like any other Platform as a Service offering. However developers at times need a greater control over the File System where they would like to copy their code to the PaaS environment for hosting. They would also like to read through the File System to verify if all the code files are deployed properly and are placed at the right place in the Azure Website File System. In most of the organizations, the developers are neither allowed to access Azure website on the portal nor read through the file system using website Console feature due to access controls and IT restrictions. For all such requirements they need to raise a ticket with centralized IT/Cloud team and get this done. Developers may not even have access to Azure portal. And many times they may need to do some custom modifications or installations on the website.
Microsoft Visual Studio Integrated Desktop Environment addresses these pain points of developers and facilitates seamless deployment to Azure (Platform as a Service) website. But not all code in the world are developed using Visual Studio IDE and Azure platform is not restricted to host only Microsoft technologies code. Azure ecosystem is large and supports an array of non-Microsoft technologies like Java, Python, and PHP to name a few. Developers would use non-Microsoft IDEs to develop non-Microsoft code and would like to host their code on Azure websites. They would love to use the IDE they have been using for ages to build the code and may not like to switch to Visual Studio. These IDEs may not be robust enough to support Azure website deployment like Visual Studio offers. Some may support but with limited functionalities.
A lot of third-party tools are available in the market to help with deployment but the good ones are not free. Also in larger organizations embracing a third-party tool would need to undergo a rigorous approval process and once the tool is approved by the concerned IT support team then only the developer can start using the tool.
Kudu REST APIs are a great help here and handle all scenarios listed above. They are simple REST endpoints and can be consumed by any programming language that supports REST calls. Kudu REST APIs bridge the gap between Azure websites and non-Microsoft applications and gets Azure PaaS closer to non-Microsoft applications.
Getting started
The best way to learn deployment using Kudu REST APIs is to build a use case and implement it. Let us build a PowerShell script that will invoke Kudu REST API zipdeploy and facilitate code deployment on Azure PaaS website. Once the code is deployed, the PowerShell script will invoke Kudu REST API vfs to list the files deployed so as to verify that all the files are successfully deployed. In the end PowerShell script will invoke Kudu REST API command that will create a log folder in the PaaS website file system and store temporary logs there.
An Azure Web App called ZipDeployGuide is already created. Steps to create this Azure Web App is not discussed here. Here we will deploy a simple ASP.net MVC application that is already created. The steps illustrated here can be used to deploy web applications built using any Azure Web App supported languages like Java, PHP, Python, etc.
Preparing the deployment package
Deployment artifacts are just to be zipped. Kudu REST API zipdeploy will unzip the zipped file to the publish root location on the Azure Web App. In our case, the publish root location on Azure Web App is:
D:\home\site\wwwroot
A default ASP.net MVC application is created using Visual Studio and the deployment artifacts are published to a local folder in the development system:
C:\KuduZipDeploy\DeploymentArtifacts
Steps for creating the ASP.net MVC application and publishing the deployment artifacts to the local folder is out of scope here as the article is focused on deploying the application and not developing the application. As a prerequisite, the deployment artifacts should be ready before trying out deployment using Kudu REST APIs.
Deployment artifacts are zipped and a zip file called as DeploymentArtifacts.zip is generated in the same location:
C:\KuduZipDeploy\DeploymentArtifacts.zip
Figure 1 below shows how the zipped folder looks.

Deployment artifacts can be zipped using any standard zip software like WinZip or 7 Zip or any other software per convenience. Kudu REST API zipdeploy expects simply zipped contents as deployment packages and hence this makes zipdeploy work on any programming platform or programming language.
Deploy zipped package to Azure Web App
Once the zipped deployment artifact DeploymentArtifacts.zip is ready, Kudu REST API zipdeploy can be invoked to unzip the zipped contents on the Azure Web App publish folder. Any programming language that is capable of invoking REST API calls can invoke zipdeploy. In this demonstration, PowerShell is used to invoke REST API.
Every Azure Web App is associated with a Kudu URL on which the Kudu REST APIs sit. This URL is needed to invoke zipdeploy API. If the Azure Web App URL is:
https://webappname.azurewebsites.net
Then the corresponding Kudu URL for the Azure Web App would be:
https://webappname.scm.azurewebsites.net
In the current context the Kudu URL for Azure Web App would be:
https://zipdeployguide.scm.azurewebsites.net
The zipdeploy API URL would be
https://zipdeployguide.scm.azurewebsites.net/api/zipdeploy
The username and Password required to deploy the zipped artifacts can be read from the Publish Profile file of the Azure Web App that can be downloaded from the Azure Portal.
Figure 2 below shows the downloaded publish profile from the Azure Web App. Refer userName and userPWD values in the publishProfile section with profileName as ZipDeployGuide – Web Deploy.
Once the Kudu REST API URL, Publish Profile User Name and Publish Profile Password is handy Kudu REST API zipdeploy can be invoked as below to deploy the zipped package. Below is the PowerShell code that invokes Kudu REST API zipdeploy to deploy the zipped artifacts. PowerShell exposes cmdlet
Invoke-RestMethod to make REST API calls. To do the deployment a POST call has to be made on REST API zipdeploy. It is highly essential to escape the $ character in the userName using backtick character (`) else PowerShell will treat this as variable instead of literal. See detailed comments (statement starting with #) in the code to get a detailed understanding of this code piece,
- # User name from WebDeploy Publish Profile. Use backtick while assigning variable content
- $userName = "`$ZipDeployGuide"
- # Password from WebDeploy Publish Profile
- $password = "{Password}"
- # Encode username and password to base64 string
- $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password)))
- # Splat all parameters together in $param hash table
- $param = @{
- # zipdeploy api url
- Uri = "https://zipdeployguide.scm.azurewebsites.net/api/zipdeploy"
- Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
- UserAgent = "powershell/1.0"
- Method = "POST"
- # Deployment Artifact Path
- InFile = "C:\KuduZipDeploy\DeploymentArtifacts.zip"
- ContentType = "multipart/form-data"
- }
- # Invoke REST call
- Invoke-RestMethod @param
Verify Package deployed on Azure Web App
Kudu REST API vfs can be used to read through the virtual file system of the Azure website. This REST API can be used in this scenario to list out all deployed artifacts in the Azure website virtual file system. To check artifacts deployed at location D:\home\site\wwwroot in the Azure Web App, the URL for the REST API would be as below where zipdeployguide in the URL is the name of the Azure Web App.
https://zipdeployguide.scm.azurewebsites.net/api/vfs/site/wwwroot
Below is the code snippet that makes a call to vfs api and get all contents deployed in the website wwwroot folder. This code can be extended further to read file contents in the sub folders as well recursively. User name and Password to read the website content can be retrieved from the publish profile of the Azure Web App as discussed earlier.
- # User name from WebDeploy Publish Profile. Back tick is needed in the
- $userName = "`$ZipDeployGuide"
- # Provide Password from WebDeploy Publish Profile
- $password = "{Password}"
- # Encode username and password to base64 string
- $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password)))
- # Splat all parameters together in $param and invoke REST API
- $param = @{
- # vfs REST API url
- Uri = "https://zipdeployguide.scm.azurewebsites.net/api/vfs/site/wwwroot/"
- Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
- UserAgent = "powershell/1.0"
- Method = "GET"
- ContentType = "application/json"
- }
- Invoke-RestMethod @param

Hadshana KamalanathanPosted Jul 14, 2018, 11:33 PM
Thank you for sharing...