Proper deployment of your Function App using ARM template

In one of my projects I'm using ARM template to deploy both App Service plan and Function App to Azure. The important thing here is the fact, that I'm using a Free tier, so e.g. Always On property is not available for me. In this post I'll show you a small gotcha, which made my functions work improperly.

The structure

Currently the part of my project we're talking about looks like this:

  • App Service plan(Free)
  • Function App containing two functions - one is triggered every 5 minutes, fetches data from a FTP server and pushes it to a queue, the second one receives items from a queue and pushes them to a storage

Really simple, what could wrong here? As you probably know, Function Apps have two modes when it comes to choosing a hosting plan:

  • Consumption Plan(you pay for what you've used)
  • App Service Plan(predefined capacity allocation)

One important thing here is one of features according to Consumption Plan - with it you don't need Always On enabled for your Function App because each time a function is triggered, it is automatically awaken and processed. If you choose App Service Plan, you have to have Always On enabled - if not, your functions may work only occasionally. Since tier Free doesn't allow you to turn on this feature, using wrong consumption plan really breaks your setup.

The problem

When working on the mentioned projected during the last weekend I realized, that when I have a one day break from work, storage is missing items from that day. When I accessed functions to check whether everything is all right, missing items were immediately pushed to it. The same was true for Application Insights attached to my Function App - there was a big gap in the data collected. The conclusion was simple - there's something wrong with a hosting plan. I had to double-check my ARM template.

The template & solution

The part of the template responsible for provisioning my Function App looked like this:

/
{
  "name": "[parameters('liczniknetFunctionAppServicePlanName')]",
  "type": "Microsoft.Web/serverfarms",
  "location": "[resourceGroup().location]",
  "apiVersion": "2014-06-01",
  "dependsOn": [],
  "tags": {
	"displayName": "liczniknet-functionapp-serviceplan"
  },
  "properties": {
	"name": "[parameters('liczniknetFunctionAppServicePlanName')]",
	"workerSize": "[parameters('liczniknetFunctionAppServicePlanWorkerSize')]",
	"numberOfWorkers": 1
  }
}

For some reason I was completely sure, that the default mode for a Function App will be Consumption Plan. There's one small thing - when a Service App plan is being provisioned, it's not aware of resources, which will be deployed further. The solution was quite simple, I was missing two additional properties:

/
{
  "name": "[parameters('liczniknetFunctionAppServicePlanName')]",
  "type": "Microsoft.Web/serverfarms",
  "location": "[resourceGroup().location]",
  "apiVersion": "2014-06-01",
  "dependsOn": [],
  "tags": {
	"displayName": "liczniknet-functionapp-serviceplan"
  },
  "properties": {
	"name": "[parameters('liczniknetFunctionAppServicePlanName')]",
	"computeMode": "Dynamic",
	"sku": "Dynamic",
	"workerSize": "[parameters('liczniknetFunctionAppServicePlanWorkerSize')]",
	"numberOfWorkers": 1
  }
}

With this new setup my Function App is deployed with a proper Hosting Plan and I don't have to awake it manually. 

Help your imagination - visualizing ARM templates with ARMVIZ

ARM templates are a great tool when you want to automate provisioning of your environment. They're customizable, somehow flexible, easy to store and modify. What they lack - as many text tools - is a touch of abstraction. Most people are sightseers - that's why it's always a good thing to see what you're doing.

I'll paint this!

ARMVIZ is a free and OSS tool, which will visualize and help to validate your ARM template on a very high level. By saying "high level" I mean, that it helps to understand the structure of a template and basic dependencies rather than underlying relations when it comes to provision resources.

The very first visualization you'll see in ARMVIZ

Working with ARMVIZ

Currently there're two possibilities to work with ARMVIZ - either you open a template stored on your disk or write a new one inside the editor. The former helps to validate whether you have all components inside a template and all dependencies work well, the latter is actually a slightly better option when it comes to write JSON than Visual Studio(especially when VS goes mad while validating a JSON schema).

ARMVIZ suggests possible values but it won't limit them to the ones available for a field

When dependencies are removed from a VM, we can clearly see, that there're some problems with our template

Summary

In current shape ARMVIZ has very limited capabilities and can act only as a quick support when you have a very complicated ARM template. On the other hand, the possibility to write and see it increases your productivity and really helps when you're struggling to understand what is related to what and why.