管理您的函數應用程式Manage your function app

在 Azure Functions 中,函數應用程式會提供個別函數的執行內容。In Azure Functions, a function app provides the execution context for your individual functions. 函數應用程式行為會套用至指定之函數應用程式所裝載的所有函數。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

若要開始,請移至 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, type the name of your function app and select it from the list. 選取函數應用程式之後,您會看到下列頁面:After selecting your function app, you see the following page:

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.

入口網站Portal

若要在入口網站中新增設定, 請選取 [新增應用程式設定], 然後新增新的機碼值組。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的索引鍵和的值來12345建立設定:The 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> \
--settings CUSTOM_FUNCTION_APP_SETTING=12345

使用應用程式設定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:

當您在本機開發函式應用程式時, 您必須在本機的設定 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 App Service 平台中執行並由此平台維護。Function apps run in, and are maintained, by the Azure App Service platform. 因此,您的函數應用程式可以存取 Azure 核心虛擬主機平台的大多數功能。As such, your function apps have access to most of the features of Azure's core web hosting platform. [平台功能] 索引標籤可供您存取許多可在函數應用程式中使用的 App Service 平台功能。The Platform features tab is where you access the many features of the App Service platform that you can use in your function apps.

注意

當函數應用程式在「取用」主控方案上執行時,並非所有 App Service 功能都可供使用。Not all App Service features are available when a function app runs on the Consumption hosting plan.

本文的其餘部分著重于 Azure 入口網站中適用于函數的下列 App Service 功能:The rest of this article focuses on the following App Service features in the Azure portal that are useful for Functions:

如需有關如何使用 App Service 設定的詳細資訊,請參閱設定 Azure App Service 設定For more information about how to work with App Service settings, see Configure Azure App Service Settings.

App Service 編輯器App Service Editor

App Service 編輯器

App Service 編輯器是一個進階的入口網站內編輯器,可供您用來修改 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 存放庫整合、執行程式碼和進行偵錯,以及修改函數應用程式設定。This enables you to integrate with the Git repository, run and debug code, and modify function app settings. 相較于內建函數編輯器, 此編輯器為您的函式提供了增強的開發環境。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 FunctionsTo learn more, see Code and test Azure Functions locally.

主控台Console

函數應用程式主控台

當您偏好從命令列與函數應用程式進行互動時,入口網站內主控台是一個理想的開發人員工具。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

App Service 的進階工具 (也稱為 Kudu) 可讓您存取函數應用程式的進階系統管理功能。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. 您也可以透過瀏覽至函數應用程式的 SCM 端點 (例如 https://<myfunctionapp>.scm.azurewebsites.net/) 來啟動 KuduYou can also launch Kudu by browsing to the SCM endpoint for your function app, like https://<myfunctionapp>.scm.azurewebsites.net/

部署中心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.

入口網站Portal

當您設定函數應用程式的 [允許的原始來源] 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.

驗證Authentication

設定函數應用程式的驗證

當函數使用 HTTP 觸發程序時,您可以要求呼叫必須先經過驗證。When functions use an HTTP trigger, you can require calls to first be authenticated. App Service 支援使用社交提供者 (例如 Facebook、Microsoft 和 Twitter) 的 Azure Active Directory 驗證和登入。App Service supports Azure Active Directory authentication and sign-in with social providers, such as Facebook, Microsoft, and Twitter. 如需設定特定驗證提供者的詳細資訊,請參閱 Azure App Service 驗證概觀For details on configuring specific authentication providers, see Azure App Service authentication overview.

後續步驟Next steps