DEV Community

Cover image for Azure Functions Tips: override the host.json settings!!
Massimo Bonanni
Massimo Bonanni

Posted on

Azure Functions Tips: override the host.json settings!!

The host.json file in Azure Functions is a configuration file that provides runtime-specific settings for your function app.
This file is located at the root of a function app project.
Some of the settings that can be configured in the host.json file include the version of the Azure Functions runtime, logging settings, function timeout duration, and settings for bindings and triggers.
The settings in the host.json file apply to all functions within a function app.

Every time you need to change some settings inside it, you need to redeploy the entire Functions App (I know that you can access to the files in the deploy directly from the portal, but it isn't a good idea!!). Fortunately, you can override the values you have in the host.json thought the appsettigs.json file (or using the configuration blade in the portal).

In particular, you can set the configuration value similar to the following:

AzureFunctionsJobHost__<HOST-CONFIG-VALUE> = value
Enter fullscreen mode Exit fullscreen mode

where <HOST-CONFIG-VALUE> is the host.json value you want to override.
For example, suppose you have the following host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "functionTimeout": "00:05:00",
  ....
}
Enter fullscreen mode Exit fullscreen mode

In that file, you set the timeout for your functions to 5 minutes. If you want to override that value to have 3 minutes of timeout, you can add the following setting in the appsetting.json file:

{
  "IsEncrypted": false,
  "Values": {
    ...
    "AzureFunctionsJobHost__functionTimeout": "00:03:00",
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode

In that case <HOST-CONFIG-VALUE> is functionTimeout.
If the value you want to override is a property of a section in the host.json config, you need to use the __ string to describe the hierarchy.

Latest comments (0)