Azure Functions 2.x 及更高版本的 host.json 参考host.json reference for Azure Functions 2.x and later

host.json 元数据文件包含对函数应用的所有函数产生影响的全局配置选项。The host.json metadata file contains global configuration options that affect all functions for a function app. 本文列出了从 Azure Functions 运行时 2.x 版开始可用的设置。This article lists the settings that are available starting with version 2.x of the Azure Functions runtime.

备注

本文适用于 Azure Functions 2.x 及更高版本。This article is for Azure Functions 2.x and later versions. 有关 Functions 1.x 中 host.json 的参考,请参阅 Azure Functions 1.x 的 host.json 参考For a reference of host.json in Functions 1.x, see host.json reference for Azure Functions 1.x.

其他函数应用配置选项在应用设置(适用于已部署的应用)或 local.settings.json 文件(用于本地开发)中进行管理。Other function app configuration options are managed in your app settings (for deployed apps) or your local.settings.json file (for local development).

host.json 中与绑定相关的配置将同样地应用于函数应用中的每个函数。Configurations in host.json related to bindings are applied equally to each function in the function app.

示例 host.json 文件Sample host.json file

以下版本 2.x+ 的示例 host.json 文件指定了所有可能的选项(不包括仅供内部使用的任何选项)。The following sample host.json file for version 2.x+ has all possible options specified (excluding any that are for internal use only).

{
    "version": "2.0",
    "extensions": {
        "cosmosDb": {},
        "durableTask": {},
        "eventHubs": {},
        "http": {},
        "queues": {},
        "sendGrid": {},
        "serviceBus": {}
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    },
    "functions": [ "QueueProcessor", "GitHubWebHook" ],
    "functionTimeout": "00:05:00",
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    },
    "managedDependency": {
        "enabled": true
    },
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    },
    "watchDirectories": [ "Shared", "Test" ]
}

本文的以下各部分解释了每个顶级属性。The following sections of this article explain each top-level property. 除非另有说明,否则其中的所有属性都是可选的。All are optional unless otherwise indicated.

CosmosDBcosmosDb

可在 Cosmos DB 触发器和绑定中查找配置设置。Configuration setting can be found in Cosmos DB triggers and bindings.

durableTaskdurableTask

可在 Durable Functions 的绑定中查找配置设置。Configuration setting can be found in bindings for Durable Functions.

eventHubeventHub

可在事件中心触发器和绑定中查找配置设置。Configuration settings can be found in Event Hub triggers and bindings.

扩展extensions

该属性返回一个对象,其中包含所有特定于绑定的设置,例如 httpeventHubProperty that returns an object that contains all of the binding-specific settings, such as http and eventHub.

extensionBundleextensionBundle

使用扩展捆绑可将一组兼容的 Functions 绑定扩展添加到函数应用。Extension bundles let you add a compatible set of Functions binding extensions to your function app. 若要了解详细信息,请参阅用于本地开发的扩展捆绑To learn more, see Extension bundles for local development.

{
    "version": "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}

extensionBundle 中提供了以下属性:The following properties are available in extensionBundle:

propertiesProperty 说明Description
idid Azure Functions 扩展捆绑的命名空间。The namespace for Azure Functions extension bundles.
版本version 要安装的捆绑包的版本。The version of the bundle to install. Functions 运行时始终选取由版本范围或间隔定义的可允许最高版本。The Functions runtime always picks the maximum permissible version defined by the version range or interval. 上述版本值允许从 1.0.0 到(但不包括)2.0.0 的所有捆绑包版本。The version value above allows all bundle versions from 1.0.0 up to but not including 2.0.0. 有关详细信息,请参阅用于指定版本范围的间隔表示法For more information, see the interval notation for specifying version ranges.

随着捆绑包中的包的变化,捆绑包版本递增。Bundle versions increment as packages in the bundle change. 当捆绑包中的包的主版本递增时,会发生主版本更改。Major version changes occur when packages in the bundle increment by a major version. 捆绑包的主版本更改通常与 Functions 运行时主版本的更改同时发生。Major version changes in the bundle usually coincide with a change in the major version of the Functions runtime.

默认捆绑包安装的当前扩展集在此 extensions.json 文件中进行枚举。The current set of extensions installed by the default bundle is enumerated in this extensions.json file.

functionsfunctions

作业宿主运行的函数的列表。A list of functions that the job host runs. 空数组表示运行所有函数。An empty array means run all functions. 仅供在本地运行时使用。Intended for use only when running locally. 在 Azure 中的函数应用中,你应当改为按照如何在 Azure Functions 中禁用函数中的步骤来禁用特定函数,而不是使用此设置。In function apps in Azure, you should instead follow the steps in How to disable functions in Azure Functions to disable specific functions rather than using this setting.

{
    "functions": [ "QueueProcessor", "GitHubWebHook" ]
}

functionTimeoutfunctionTimeout

指示所有函数的超时持续时间。Indicates the timeout duration for all functions. 它采用 timespan 字符串格式。It follows the timespan string format. 在无服务器消耗计划中,有效范围为 1 秒至 10 分钟,默认值为 5 分钟。In a serverless Consumption plan, the valid range is from 1 second to 10 minutes, and the default value is 5 minutes.

在专用(应用服务)计划中,没有总体限制,默认值为 30 分钟。In a Dedicated (App Service) plan, there is no overall limit, and the default value is 30 minutes. -1 指示无限执行,但建议保留固定上限。A value of -1 indicates unbounded execution, but keeping a fixed upper bound is recommended.

{
    "functionTimeout": "00:05:00"
}

healthMonitorhealthMonitor

主机运行状况监视器的配置设置。Configuration settings for Host health monitor.

{
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    }
}
propertiesProperty 默认Default 说明Description
已启用enabled truetrue 指定是否启用此功能。Specifies whether the feature is enabled.
healthCheckIntervalhealthCheckInterval 10 秒10 seconds 定期后台运行状况检查之间的时间间隔。The time interval between the periodic background health checks.
healthCheckWindowhealthCheckWindow 2 分钟2 minutes healthCheckThreshold 设置结合使用的滑动时间窗口。A sliding time window used in conjunction with the healthCheckThreshold setting.
healthCheckThresholdhealthCheckThreshold 66 在启动主机回收之前,运行状况检查可以失败的最大次数。Maximum number of times the health check can fail before a host recycle is initiated.
counterThresholdcounterThreshold 0.800.80 性能计数器将被视为不正常的阈值。The threshold at which a performance counter will be considered unhealthy.

httphttp

可在 http 触发器和绑定中查找配置设置。Configuration settings can be found in http triggers and bindings.

managedDependencymanagedDependency

托管依赖项是一项功能,目前仅支持基于 PowerShell 的函数。Managed dependency is a feature that is currently only supported with PowerShell based functions. 它使依赖项可以由服务自动管理。It enables dependencies to be automatically managed by the service. enabled 属性设置为 true 时,requirements.psd1 文件会被处理。When the enabled property is set to true, the requirements.psd1 file is processed. 发布任何次要版本时会更新依赖项。Dependencies are updated when any minor versions are released.

{
    "managedDependency": {
        "enabled": true
    }
}

queuesqueues

可在存储队列触发器和绑定中查找设置。Configuration settings can be found in Storage queue triggers and bindings.

SendGridsendGrid

可在 SendGrid 触发器和绑定中查找配置设置。Configuration setting can be found in SendGrid triggers and bindings.

serviceBusserviceBus

可在服务总线触发器和绑定中查找配置设置。Configuration setting can be found in Service Bus triggers and bindings.

singletonsingleton

单一实例锁行为的配置设置。Configuration settings for Singleton lock behavior. 有关详细信息,请参阅有关单一实例支持的 GitHub 问题For more information, see GitHub issue about singleton support.

{
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    }
}
propertiesProperty 默认Default 说明Description
lockPeriodlockPeriod 00:00:1500:00:15 占用函数级锁的时间段。The period that function level locks are taken for. 锁自动续订。The locks auto-renew.
listenerLockPeriodlistenerLockPeriod 00:01:0000:01:00 占用侦听器锁的时间段。The period that listener locks are taken for.
listenerLockRecoveryPollingIntervallistenerLockRecoveryPollingInterval 00:01:0000:01:00 在启动时无法获取侦听器锁的情况下,用于恢复侦听器锁的时间间隔。The time interval used for listener lock recovery if a listener lock couldn't be acquired on startup.
lockAcquisitionTimeoutlockAcquisitionTimeout 00:01:0000:01:00 运行时尝试获取锁的最长时间。The maximum amount of time the runtime will try to acquire a lock.
lockAcquisitionPollingIntervallockAcquisitionPollingInterval 不适用n/a 尝试获取锁的间隔时间。The interval between lock acquisition attempts.

版本version

此值指示 host.json 的架构版本。This value indicates the schema version of host.json. 面向 v2 运行时或更高版本的函数应用需要版本字符串 "version": "2.0"The version string "version": "2.0" is required for a function app that targets the v2 runtime, or a later version. v2 和 v3 之间没有 host.json 架构更改。There are no host.json schema changes between v2 and v3.

watchDirectorieswatchDirectories

应该监视其更改情况的一组共享代码目录A set of shared code directories that should be monitored for changes. 确保当这些目录中的代码发生更改时,函数会拾取这些更改。Ensures that when code in these directories is changed, the changes are picked up by your functions.

{
    "watchDirectories": [ "Shared" ]
}

后续步骤Next steps