Different host.json for Debug and Release for Azure Functions

Viewed 435

For my azure function I've a host.json where I set the functionTimeout. I've to change the value before each deployment (release) and change it back for debugging purposes.

Is there a way to have two different host.json files - one for release and one for debug?

1 Answers

Don't think you can add host.staging.json, host.dev.json or host.prod.json to a Function instead try the settings override approach:

Override host.json values:

There may be instances where you wish to configure or modify specific settings in a host.json file for a specific environment, without changing the host.json file itself. You can override specific host.json values be creating an equivalent value as an application setting. When the runtime finds an application setting in the format AzureFunctionsJobHost__path__to__setting, it overrides the equivalent host.json setting located at path.to.setting in the JSON. When expressed as an application setting, the dot (.) used to indicate JSON hierarchy is replaced by a double underscore (__).

For example, say that you wanted to disable Application Insight sampling when running locally. If you changed the local host.json file to disable Application Insights, this change might get pushed to your production app during deployment. The safer way to do this is to instead create an application setting as "AzureFunctionsJobHost__logging__applicationInsights__samplingSettings__isEnabled":"false" in the local.settings.json file. You can see this in the following local.settings.json file, which doesn't get published:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "{storage-account-connection-string}",
        "FUNCTIONS_WORKER_RUNTIME": "{language-runtime}",
        "AzureFunctionsJobHost__logging__applicationInsights__samplingSettings__isEnabled":"false"
    }
}
Related