Azure Functions 簡介Introduction to Azure Functions

Azure Functions 是無伺服器解決方案,可讓您撰寫較少的程式碼、維護較少的基礎結構,並節省成本。Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. 雲端基礎結構會提供讓應用程式保持執行所需的所有最新資源,而不需要擔心部署和維護伺服器。Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running.

您可以著重於最重要的程式碼片段,讓 Azure Functions 處理其餘部分。You focus on the pieces of code that matter most to you, and Azure Functions handles the rest.

我們經常會建置系統來回應一系列的重大事件。We often build systems to react to a series of critical events. 無論是建立 Web API、回應資料庫變更、處理 IoT 資料流程,甚至是管理訊息佇列,每個應用程式都需要一種方法,可在這些事件發生時執行某些程式碼。Whether you're building a web API, responding to database changes, processing IoT data streams, or even managing message queues - every application needs a way to run some code as these events occur.

為了符合此需求,Azure Functions 在兩種重要的方式中提供「隨選計算」。To meet this need, Azure Functions provides "compute on-demand" in two significant ways.

首先,Azure Functions 可讓您將系統的邏輯實作為容易使用的程式碼區塊。First, Azure Functions allows you to implement your system's logic into readily available blocks of code. 這些程式碼區塊稱為「函式」。These code blocks are called "functions". 當您需要回應重大事件時,可以隨時執行不同的函式。Different functions can run anytime you need to respond to critical events.

第二,隨著要求的增加,Azure Functions 會符合需求,視需要提供多個資源和函式執行個體 - 但只有在必要時才提供。Second, as requests increase, Azure Functions meets the demand with as many resources and function instances as necessary - but only while needed. 隨著要求的下降,系統會自動捨棄任何額外的資源和應用程式執行個體。As requests fall, any extra resources and application instances drop off automatically.

所有計算資源來自何處?Where do all the compute resources come from? Azure Functions 會視需要提供多個或較少的計算資源,以符合您的應用程式需求。Azure Functions provides as many or as few compute resources as needed to meet your application's demand.

視需要提供計算資源,是 Azure Functions 中無伺服器運算的要素。Providing compute resources on-demand is the essence of serverless computing in Azure Functions.

案例Scenarios

在許多情況下,函式會與雲端服務整合,以提供功能豐富的實作。In many cases, a function integrates with an array of cloud services to provide feature-rich implementations.

以下是常見,但「不是全部」的 Azure Functions 案例集合。The following are a common, but by no means exhaustive, set of scenarios for Azure Functions.

如果您想要...If you want to... 接著...then...
建置 Web APIBuild a web API 使用 HTTP 觸發程序為您的 Web 應用程式實作端點Implement an endpoint for your web applications using the HTTP trigger
處理檔案上傳Process file uploads Blob 儲存體中上傳或變更檔案時執行程式碼Run code when a file is uploaded or changed in blob storage
建置無伺服器工作流程Build a serverless workflow 使用 Durable Functions 將一系列函式鏈結在一起Chain a series of functions together using durable functions
回應資料庫變更Respond to database changes Cosmos DB 中建立或更新文件時,執行自訂邏輯 Cosmos DBRun custom logic when a document is created or updated in Cosmos DB
執行排程的工作Run scheduled tasks 設定時間執行程式碼Execute code at set times
建立可靠的訊息佇列系統Create reliable message queue systems 使用佇列儲存體服務匯流排事件中樞處理訊息佇列Process message queues using Queue Storage, Service Bus, or Event Hubs
分析 IoT 資料流Analyze IoT data streams 收集和處理來自 IoT 裝置的資料Collect and process data from IoT devices
即時處理資料Process data in real time 使用函式和 SignalR 在當下回應資料Use Functions and SignalR to respond to data in the moment

建置函式時,可使用下列選項和資源:As you build your functions, you have the following options and resources available:

後續步驟Next Steps