How to Deploy your Azure Function Automatically with ARM template (4 different ways)

(version en français ici)

It’s so nice to be able to add some serverless components in our solution to make them better in a snap. But how do we manage them? In this post, I will explain how to create an Azure resource manager (ARM) template to deploy any Azure Function and show how I used this structure to deploy an open-source project I’ve been working on these days.

Part 1 — The ARM template

An ARM template is a JSON file that describes our architecture. To deploy an Azure Function we need at least three recourses: a functionApp, a service plan, and a storage account.

The FunctionApp is, of course, our function. The service plan could be set as dynamic or describe the type of resource that will be used by your function. The storage account is where is our code.

In the previous image, you can see how those components interact more with each other. Inside the Function, we will have a list of properties. One of those properties will be the Runtime, for example, in the AZUnzipEverything demo, it will be dotnet. Another property will be the connection string to our storage account that is also part of our ARM template. Since that resource doesn’t exist yet, we will need to use the dynamic code.

The Function node will contain a sub-resource of type storageAccount. This is where we will specify where is our code, so it cant be clone to Azure.

Building ARM for a Simple Function

Let’s see a template for a simple Azure Function that doesn’t require any dependency, and we will examine it after.

You can use any text editor to edit your ARM template. However, the bundle VSCode with the extensions Azure Resource Manager Tools and Azure Resource Manager Snippets is particularly efficient.

The Storage Account

The first resources listed in the template is the Account Storage. There nothing specific about it.

The Service Plan

The service plan is the second resource in the list. It’s important to notice that to be able to use the SKU Dynamic you will need at least the API version of apiVersion to be “2018–02–01”. Then you specify the SKU.

Of course, you can use the other SKU if you prefer.

The Function App

Final resources added to the mixt, and this is where all the pieces are getting together. It’s important to notice that the other in which the resources are listed are not considered by Azure while deploying (it’s only for us ;) ). To let Azure knows you need to add dependencies.

This way the Azure Function will be created after the service plan and the storage account are available. Then in the properties, we will be able to build the ConnectionString to the blob storage using a reference.

The last piece of the puzzle is the sub-resource sourcecontrol inside the FunctionApp. This will define where Azure should clone the code from and in which branch.

To be sure that everything is fully automatic the properties publishRunbook and IsManualIntegration must be set as true. Otherwise, you will need to do a synchronization between your Git (in this case on GitHub), and the Git in Azure.

There is excellent documentation that explains many deferent scenarios to Automate resource deployment for your function app in Azure Functions

Real Sample: Azure Unzip Everything

To deploy the project AzUnzipEverything available on GitHub, I needed one more Azure Storage with pre-define containers (folders).

Of course, all the source code of both the Azure Function and the ARM template are available on GitHub, but let me highlight how the containers are defined from an ARM template.

Just like with sourcecontrol , we will need to add a list of sub-resources to our storage account. The name MUST start by 'default/'.

Part 2 — Four Deployment Options

Now that we have a template that describes our needs we just need to deploy it. There are multiple ways it could be done, but let’s see four of them.

Deploy from the Azure Portal

Navigate to the Azure Portal (, from your favorite browser and search for “deploy a custom template” directly in the search bar located at the top of the screen (in the middle). Or go at One in the Custom deployment page, click on the link Build your own template in the editor. From there, you can copy-paste or upload your ARM template. You need to save it to see the real deployment form.

Deploy with a script

Would it be in PowerShell or in Azure CLI you can easily deploy your template with these two commands.

In Azure CLI

In PowerShell

Deploy to Azure Button

One of the best way to help people to deploy your solution in their Azure subscription is the Deploy to Azure Button.

You need to create an image link (in HTML or Markdown) to this to a special destination build in two-part.

The first one is a link to the Azure Portal:

And the second one is the location of your ARM template:

However, this URL needs to be encoded. There is plenty of encoders online, but you can also do it from the terminal with the following command (A big thanks to @BrettMiller_IT who showed me this trick during one of my live streams).

Clicking the button will bring the user at the same page on the Azure Portal but in the user subscription.

Azure DevOps Pipeline

From the Azure DevOps portal (, select your project and create a new Release Pipeline. Click on the + Add an artifact button to connect your Git repository.

Once it's added, you need to add a task the current job. Click on the link 1 job, 0 task (4). Now you just need to specify your Azure subscription, the name of the resource group and select the location of your ARM template inside your repository. To make the deployment automatic with each push in the repository, click that little lightning bolt and enable the Continuous deployment trigger.


Voila, you know have four different ways to deploy your Azure Function automatically. But don't take my word for it, try it yourself! If you need more details you can visit the project on GitHub or watch this video where I demo the content of this post.

Originally published at on July 19, 2019.

Cloud Advocate, I share the best practices and my projects online in English and in French. 🎦