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 Azu

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. 

Comments (2) -

125922 849396I ran into this page accidentally, surprisingly, this really is a fantastic site. The web site owner has done a fantastic job writing/collecting articles to post, the information here is actually insightful.  You just secured yourself a guarenteed reader. 55294

Kamil Mrzygłód 6/20/2017 12:08:32 PM

Thank you!

Add comment