管理函数应用Manage your function app

在 Azure Functions 中,Function App 提供各个函数的执行上下文。In Azure Functions, a function app provides the execution context for your individual functions. Function App 行为适用于由给定 Function App 托管的所有函数。Function app behaviors apply to all functions hosted by a given function app. 函数应用中的所有函数必须使用同一语言All functions in a function app must be of the same language.

函数应用中的各个函数一起部署并一起缩放。Individual functions in a function app are deployed together and are scaled together. 同一函数应用中的所有函数在函数应用缩放时共享每个实例的资源。All functions in the same function app share resources, per instance, as the function app scales.

将为每个函数应用单独定义连接字符串、环境变量以及其他应用程序设置。Connection strings, environment variables, and other application settings are defined separately for each function app. 必须在函数应用之间共享的任何数据都应该以外部方式存储在持久存储中。Any data that must be shared between function apps should be stored externally in a persisted store.

本文介绍如何配置和管理函数应用。This article describes how to configure and manage your function apps.


许多配置选项也可通过 Azure CLI 进行管理。Many configuration options can also be managed by using the Azure CLI.

在 Azure 门户中开始Get started in the Azure portal

  1. 要开始,请转到 Azure 门户,并使用 Azure 帐户登录。To begin, go to the Azure portal and sign in to your Azure account. 在门户顶端的搜索栏中,输入函数应用的名称,并从列表中将其选中。In the search bar at the top of the portal, enter the name of your function app and select it from the list.

  2. 在左窗格的“配置”下,选择“配置”**** ****。Under Settings in the left pane, select Configuration.

    Azure 门户中的函数应用概述

可以从概述页导航到管理函数应用所需的所有内容,特别是 应用程序设置平台功能You can navigate to everything you need to manage your function app from the overview page, in particular the Application settings and Platform features.

应用程序设置Application settings

“应用程序设置”选项卡维护函数应用使用的设置****。The Application settings tab maintains settings that are used by your function app. 这些设置是加密存储的,必须选择“显示值”**** 才能查看门户中的值。These settings are stored encrypted, and you must select Show values to see the values in the portal. 也可使用 Azure CLI 访问应用程序设置。You can also access application settings by using the Azure CLI.


若要在门户中添加设置,请选择“新建应用程序设置”**** 并添加新的键值对。To add a setting in the portal, select New application setting and add the new key-value pair.

Azure 门户中的函数应用设置。

Azure CLIAzure CLI

az functionapp config appsettings list 命令返回现有的应用程序设置,如以下示例所示:The az functionapp config appsettings list command returns the existing application settings, as in the following example:

az functionapp config appsettings list --name <FUNCTION_APP_NAME> \
--resource-group <RESOURCE_GROUP_NAME>

az functionapp config appsettings set 命令添加或更新某个应用程序设置。The az functionapp config appsettings set command adds or updates an application setting. 以下示例创建的设置包含的键其名称为 CUSTOM_FUNCTION_APP_SETTING,其值为 12345The following example creates a setting with a key named CUSTOM_FUNCTION_APP_SETTING and a value of 12345:

az functionapp config appsettings set --name <FUNCTION_APP_NAME> \
--resource-group <RESOURCE_GROUP_NAME> \

使用应用程序设置Use application settings

还可以在代码中将函数应用设置值读取为环境变量。The function app settings values can also be read in your code as environment variables. 有关详细信息,请参阅以下特定于语言的参考主题的“环境变量”部分:For more information, see the Environment variables section of these language-specific reference topics:

在本地开发函数应用时,必须将这些值的本地副本保留在 local.settings.json 项目文件中。When you develop a function app locally, you must maintain local copies of these values in the local.settings.json project file. 若要了解详细信息,请参阅本地设置文件To learn more, see Local settings file.

平台功能Platform features

函数应用在 Azure 应用服务平台中运行,并由该平台维护。Function apps run in, and are maintained by, the Azure App Service platform. 在这种情况下,Function App 有权访问 Azure 核心 Web 托管平台的大多数功能。As such, your function apps have access to most of the features of Azure's core web hosting platform. 可在左侧窗格中访问可用于函数应用的应用服务平台中的许多功能。The left pane is where you access the many features of the App Service platform that you can use in your function apps.


Function App 运行于消耗托管计划中时,并非所有应用服务功能均可用。Not all App Service features are available when a function app runs on the Consumption hosting plan.

本文的其余部分侧重于 Azure 门户中以下可用于 Functions 的应用服务功能:The rest of this article focuses on the following App Service features in the Azure portal that are useful for Functions:

若要深入了解如何使用应用服务设置,请参阅配置 Azure 应用服务设置For more information about how to work with App Service settings, see Configure Azure App Service Settings.

应用服务编辑器App Service editor


应用服务编辑器是一种高级的门户内编辑器,可用于修改诸如 JSON 配置文件和代码文件等内容。The App Service editor is an advanced in-portal editor that you can use to modify JSON configuration files and code files alike. 选择此选项会启动单独的浏览器选项卡和基本编辑器。Choosing this option launches a separate browser tab with a basic editor. 借此,可与 Git 存储库集成、运行和调试代码,并可修改 Function App 设置。This enables you to integrate with the Git repository, run and debug code, and modify function app settings. 同内置的函数编辑器相比,此编辑器为 Functions 提供了增强的开发环境。This editor provides an enhanced development environment for your functions compared with the built-in function editor.

建议你考虑在本地计算机上开发函数。We recommend that you consider developing your functions on your local computer. 在本地开发项目并将其发布到 Azure 时,项目文件在门户中处于只读状态。When you develop locally and publish to Azure, your project files are read-only in the portal. 若要了解详细信息,请参阅在本地对 Azure Functions 进行编码和测试To learn more, see Code and test Azure Functions locally.


Function App 控制台

要从命令行与 Function App 交互时,门户内控制台就是非常合适的开发人员工具。The in-portal console is an ideal developer tool when you prefer to interact with your function app from the command line. 常见命令包括创建和导航目录与文件,以及执行批处理文件和脚本。Common commands include directory and file creation and navigation, as well as executing batch files and scripts.

在本地进行开发时,建议使用 Azure Functions Core ToolsAzure CLIWhen developing locally, we recommend using the Azure Functions Core Tools and the Azure CLI.

高级工具 (Kudu)Advanced tools (Kudu)

配置 Kudu

应用服务的高级工具(也称为 Kudu)提供对 Function App 高级管理功能的访问。The advanced tools for App Service (also known as Kudu) provide access to advanced administrative features of your function app. 从 Kudu 中,可以管理系统信息、应用设置、环境变量、站点扩展、HTTP 头和服务器变量。From Kudu, you manage system information, app settings, environment variables, site extensions, HTTP headers, and server variables. 也可以通过浏览到 Function App 的 SCM 终结点(如 https://<myfunctionapp>.scm.chinacloudsites.cn/),启动 Kudu****You can also launch Kudu by browsing to the SCM endpoint for your function app, like https://<myfunctionapp>.scm.chinacloudsites.cn/

部署中心Deployment Center

使用源代码管理解决方案来开发和维护函数代码时,可以使用部署中心通过源代码管理进行生成和部署。When you use a source control solution to develop and maintain your functions code, Deployment Center lets you build and deploy from source control. 进行更新时,会生成项目并将其部署到 Azure。Your project is built and deployed to Azure when you make updates. 有关详细信息,请参阅 Azure Functions 中的部署技术For more information, see Deployment technologies in Azure Functions.

跨域资源共享Cross-origin resource sharing

为了防止在客户端执行恶意代码,新式的浏览器会阻止 Web 应用程序向正在单独的域中运行的资源发送请求。To prevent malicious code execution on the client, modern browsers block requests from web applications to resources running in a separate domain. 跨域资源共享 (CORS) 允许 Access-Control-Allow-Origin 标头声明允许哪些域调用函数应用上的终结点。Cross-origin resource sharing (CORS) lets an Access-Control-Allow-Origin header declare which origins are allowed to call endpoints on your function app.


配置函数应用的“允许的域”列表时,****Access-Control-Allow-Origin 标头会自动添加到函数应用中 HTTP 终结点发出的所有响应。When you configure the Allowed origins list for your function app, the Access-Control-Allow-Origin header is automatically added to all responses from HTTP endpoints in your function app.

配置函数应用的 CORS 列表

使用星号 (*) 时,会忽略所有其他的域。When the wildcard (*) is used, all other domains are ignored.

使用 az functionapp cors add 命令将域添加到“允许的域”列表。Use the az functionapp cors add command to add a domain to the allowed origins list. 以下示例添加 contoso.com 域:The following example adds the contoso.com domain:

az functionapp cors add --name <FUNCTION_APP_NAME> \
--resource-group <RESOURCE_GROUP_NAME> \
--allowed-origins https://contoso.com

使用 az functionapp cors show 命令列出目前允许的域。Use the az functionapp cors show command to list the current allowed origins.


配置 Function App 的身份验证

函数使用 HTTP 触发器时,可以要求首先对调用进行身份验证。When functions use an HTTP trigger, you can require calls to first be authenticated. 应用服务支持 Azure Active Directory 身份验证和使用社交提供程序登录。App Service supports Azure Active Directory authentication and sign-in with social providers. 有关配置特定身份验证提供程序的详细信息,请参阅 Azure 应用服务身份验证概述For details on configuring specific authentication providers, see Azure App Service authentication overview.

后续步骤Next steps