<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Microsoft_Azure_Functions</id>
	<title>Microsoft Azure Functions - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Microsoft_Azure_Functions"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Microsoft_Azure_Functions&amp;action=history"/>
	<updated>2026-06-27T16:03:27Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=Microsoft_Azure_Functions&amp;diff=2884817&amp;oldid=prev</id>
		<title>imported&gt;AromaTake：​/* 功能 */ 調整格式、排版。調整&lt;syntaxhighlight&gt;的lang參數</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Microsoft_Azure_Functions&amp;diff=2884817&amp;oldid=prev"/>
		<updated>2025-01-20T03:16:25Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;功能：​&lt;/span&gt; 調整格式、排版。調整&amp;lt;syntaxhighlight&amp;gt;的lang參數&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Microsoft Azure Functions&amp;#039;&amp;#039;&amp;#039; 是 [[Microsoft Azure]] 平台上，提供[[無伺服器計算]]架構 (Serverless Computing) 的服務，允許開發人員在不用接觸與管理伺服器的情況下，編寫小型的處理程式以處理雲端上的訊息或事件。&lt;br /&gt;
&lt;br /&gt;
Azure Functions 於微軟 Build 2016 大會上宣布，於同年11月15日正式 GA (General Availability)。&lt;br /&gt;
&lt;br /&gt;
Azure Functions 已廣泛於用如 [[Azure Bot Services]]、[[Azure IoT Suite]]、[[Azure Logic App]] 等服務串聯。&lt;br /&gt;
&lt;br /&gt;
== 簡介 ==&lt;br /&gt;
&lt;br /&gt;
Azure Functions 是以 Azure Web App 開發時所建立的 [[Microsoft Azure Azure Web Jobs]] 為基礎所開發的一個服務，Web Jobs 在開發時就已經支援多語言 (包含 [[Bash]], [[批次檔]], [[C♯|C#]], [[node.js]], [[PowerShell]], [[F#]], [[Python]] 與 [[PHP]] 等) 的執行環境，因此在發展 Azure Functions 時，也將 Web Jobs 的多語言能力移植到 Azure Functions，同時基於無伺服器的架構，Azure Functions 只要求開發人員在 Azure 的管理介面上撰寫程式碼，即可立即測試與執行，不必擔心背後的資源分配與伺服器管理的問題。&lt;br /&gt;
&lt;br /&gt;
Azure Functions 在設計上以函數 (function) 會有的特性來規劃，一個函數本身會有輸入 (input)、處理 (process) 與輸出 (output) 三個部份，微軟將輸入和輸出進行抽象化的處理，以繫結 (binding) 來替代 &amp;lt;ref&amp;gt;{{Cite web |url=https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-triggers-bindings |title=Azure Functions 觸發程序和繫結概念 |accessdate=2017-05-28 |archive-date=2020-10-24 |archive-url=https://web.archive.org/web/20201024233814/https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-triggers-bindings |dead-url=no }}&amp;lt;/ref&amp;gt;。&lt;br /&gt;
* 輸入繫結 (input binding) 表示函數會於繫結指定的條件發生時觸發，並將條件所需的參數傳到函數作為輸入的參數 (argument)。&lt;br /&gt;
* 輸出繫結 (output binding) 表示函數會輸出成指定的格式，通常作為回傳值 (return value)。&lt;br /&gt;
&lt;br /&gt;
Azure Functions 如同其他 [[Azure App Services|Azure應用服務]] 一般，執行於 App Service Plan (應用服務計畫)&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-scale |title=Azure Functions 取用和 App Service 方案 |accessdate=2017-05-28 |archive-date=2020-10-25 |archive-url=https://web.archive.org/web/20201025174411/https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-scale |dead-url=no }}&amp;lt;/ref&amp;gt; 之上，不過為了要達到無伺服器架構的目標，Azure Functions 還多了一個使用模式，稱為消費計畫 (Consumption Plan)，以執行次數 (Executions) 和執行時的資源耗用量 (Resource Consumption) 為計費基礎 &amp;lt;ref&amp;gt;{{Cite web |url=https://azure.microsoft.com/en-us/pricing/details/functions/ |title=Azure Functions Pricing |accessdate=2017-05-28 |archive-date=2020-11-12 |archive-url=https://web.archive.org/web/20201112021909/https://azure.microsoft.com/en-us/pricing/details/functions/ |dead-url=no }}&amp;lt;/ref&amp;gt;，但使用者可選擇要用原始的 App Service Plan 還是要使用計量級的 Consumption Plan 作為計費單位。&lt;br /&gt;
&lt;br /&gt;
== 功能 ==&lt;br /&gt;
&lt;br /&gt;
Azure Functions 基於無伺服器管理架構，因此其功能大多數都落在程式碼的開發、繫結的設定與安全金鑰的管理，當然也可以依需求進一步的設定其所處的 App Service Plan (即使是 Consumption Plan 也有) 的進階設定，例如加上 SSL 或增修應用程式組態檔的設定等等。&lt;br /&gt;
&lt;br /&gt;
=== 程式碼管理 ===&lt;br /&gt;
&lt;br /&gt;
Azure Functions 允許開發人員直接編寫函數的程式碼，也就是處理 (Process) 這個部份，基於與函數的繫結的整合，微軟提供了數個樣板 (template) 給開發人員選用，每個支援的繫結都會有一個樣板，開發人員不需費心於思考如何在函數中使用繫結，只要在函數的本體中編寫處理的程式碼即可。&lt;br /&gt;
&lt;br /&gt;
例如使用 HTTP 觸發 (即送 HTTP 要求給該函數) 的 C# 程式碼如下：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
public static Task&amp;lt;HttpResponseMessage&amp;gt; Run(HttpRequestMessage request, string category, int? id, TraceWriter log)&lt;br /&gt;
    {&lt;br /&gt;
        if (id == null)&lt;br /&gt;
           return  req.CreateResponse(HttpStatusCode.OK, $&amp;quot;All {category} items were requested.&amp;quot;);&lt;br /&gt;
        else&lt;br /&gt;
           return  req.CreateResponse(HttpStatusCode.OK, $&amp;quot;{category} item with id = {id} has been requested.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
而同樣功能的 node.js 程式碼如下：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
module.exports = function (context, req) {&lt;br /&gt;
&lt;br /&gt;
        var category = context.bindingData.category;&lt;br /&gt;
        var id = context.bindingData.id;&lt;br /&gt;
&lt;br /&gt;
        if (!id) {&lt;br /&gt;
            context.res = {&lt;br /&gt;
                // status: 200, /* Defaults to 200 */&lt;br /&gt;
                body: &amp;quot;All &amp;quot; + category + &amp;quot; items were requested.&amp;quot;&lt;br /&gt;
            };&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
            context.res = {&lt;br /&gt;
                // status: 200, /* Defaults to 200 */&lt;br /&gt;
                body: category + &amp;quot; item with id = &amp;quot; + id + &amp;quot; was requested.&amp;quot;&lt;br /&gt;
            };&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        context.done();&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
範本會先為開發人員設定好參數，開發人員只要填入處理的程式即可。&lt;br /&gt;
&lt;br /&gt;
另外，Azure Functions 也支援由 git 部署&amp;lt;ref&amp;gt;{{Cite web |url=https://shellmonger.com/2016/12/02/deploying-azure-functions-automatically/ |title=Deploying Azure Functions Automatically |access-date=2017-05-28 |archive-url=https://web.archive.org/web/20170910025823/https://shellmonger.com/2016/12/02/deploying-azure-functions-automatically/ |archive-date=2017-09-10 |dead-url=yes }}&amp;lt;/ref&amp;gt;，然而若使用 git 部署時，Azure Portal 上的程式碼編輯器會強制停用。&lt;br /&gt;
&lt;br /&gt;
=== 繫結 ===&lt;br /&gt;
&lt;br /&gt;
繫結決定了函數的輸入、觸發時間與輸出，Azure Functions 支援了下列的觸發程序、輸入與輸出。由於觸發程序和輸入參數可以不同，因此下表中無輸入但有觸發支援時，觸發的參數會作為輸入的參數。&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! 類型 !! 觸發 !! 輸入 !! 輸出&lt;br /&gt;
|-&lt;br /&gt;
| 排程 || 支援 (設定的時間或週期到時) ||  || &lt;br /&gt;
|-&lt;br /&gt;
| HTTP || 支援 (接到由 REST 或 WebHook 發送的 HTTP 要求時) || || 支援&lt;br /&gt;
|-&lt;br /&gt;
| Blob || 支援 (Azure Storage Blob 監控的容器有資料新增或更新時) || 支援 || 支援&lt;br /&gt;
|-&lt;br /&gt;
| 事件 || 支援 (EventHub 有事件進入時) || || 支援&lt;br /&gt;
|-&lt;br /&gt;
| 佇列 || 支援 (Azure Storage Queue 佇列內有訊息時) || || 支援&lt;br /&gt;
|-&lt;br /&gt;
| 佇列和主題 || 支援 (Azure Service Bus Queue 佇列或 Topic 主題內有訊息時)  || || 支援&lt;br /&gt;
|-&lt;br /&gt;
| 儲存體資料表 || || 支援 || 支援&lt;br /&gt;
|-&lt;br /&gt;
| SQL 資料表 || || 支援 || 支援&lt;br /&gt;
|-&lt;br /&gt;
| NoSQL 資料庫 || || 支援 || 支援&lt;br /&gt;
|-&lt;br /&gt;
| 通知訊息 || || || 支援&lt;br /&gt;
|-&lt;br /&gt;
| Twilio SMS 服務 || || || 支援&lt;br /&gt;
|-&lt;br /&gt;
| SendGrid || || || 支援&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
每個輸入、輸出繫結與觸發程序也會有必要的參數設定 (例如排程需要設定執行週期、Blob 需要設定監控的儲存體帳戶與容器等等)。&lt;br /&gt;
&lt;br /&gt;
繫結的設定除了可在使用者介面上設定外，也可使用每個函數都有的 function.json 檔案設定，例如下列設定表示了監控 blob 的輸入，如果有輸入就觸發函數，並且將函數的輸出指定為另一個 blob 的繫結。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;bindings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;image&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;blobTrigger&amp;quot;,&lt;br /&gt;
      &amp;quot;path&amp;quot;: &amp;quot;sample-images/{filename}&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;in&amp;quot;,&lt;br /&gt;
      &amp;quot;connection&amp;quot;: &amp;quot;MyStorageConnection&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;imageSmall&amp;quot;,&lt;br /&gt;
      &amp;quot;type&amp;quot;: &amp;quot;blob&amp;quot;,&lt;br /&gt;
      &amp;quot;path&amp;quot;: &amp;quot;sample-images-sm/{filename}&amp;quot;,&lt;br /&gt;
      &amp;quot;direction&amp;quot;: &amp;quot;out&amp;quot;,&lt;br /&gt;
      &amp;quot;connection&amp;quot;: &amp;quot;MyStorageConnection&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 存取控制 ===&lt;br /&gt;
&lt;br /&gt;
使用 HTTP 繫結作為輸入的函數 (通常用於 [[REST]] 與 [[WebHook]])，Azure Functions 會另外提供金鑰 (Key) 給開發人員使用，以作為存取控制的方法&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-bindings-http-webhook#a-nameworking-with-keysa使用金鑰 |title=Azure Functions HTTP 和 Webhook 繫結 |accessdate=2017-05-28 |archive-date=2019-02-17 |archive-url=https://web.archive.org/web/20190217061240/https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-bindings-http-webhook#a-nameworking-with-keysa使用金鑰 |dead-url=no }}&amp;lt;/ref&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
金鑰預設有兩種：&lt;br /&gt;
&lt;br /&gt;
* 主機金鑰 (master key)：所有建於此應用程式內的所有函數都可使用。&lt;br /&gt;
* 函數金鑰 (function key): 只有金鑰所屬的函數可使用。&lt;br /&gt;
&lt;br /&gt;
除了上面兩個預設的金鑰外，開發人員也可建立自己的金鑰，並決定存取權限是限制於函數，還是要支援所有的函數。&lt;br /&gt;
&lt;br /&gt;
== 開發人員支援 ==&lt;br /&gt;
&lt;br /&gt;
Azure Functions 除了提供 Azure Portal 上的程式碼編修，以及採用 git 的持續整合的程式碼管理方式外，也為開發人員在地端的作業提供了 Azure Function Runtime，以加速開發人員在地端的開發與測試。&lt;br /&gt;
&lt;br /&gt;
[[Visual Studio Code]] 也有套件支援 Azure Functions 的開發。&lt;br /&gt;
&lt;br /&gt;
== 參考 ==&lt;br /&gt;
{{Reflist|30em}}&lt;br /&gt;
&lt;br /&gt;
== 相关条目 ==&lt;br /&gt;
* [[AWS Lambda]]&lt;br /&gt;
&lt;br /&gt;
== 外部連結 ==&lt;br /&gt;
* [https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-overview Introducing Azure Functions] {{Wayback|url=https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-overview |date=20201014061228 }}&lt;br /&gt;
* [https://azure.microsoft.com/zh-tw/services/functions/ Azure Functions Overview] {{Wayback|url=https://azure.microsoft.com/zh-tw/services/functions/ |date=20201129001232 }}&lt;br /&gt;
&lt;br /&gt;
{{雲端運算}}&lt;br /&gt;
{{Microsoft Azure}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Microsoft Azure]]&lt;/div&gt;</summary>
		<author><name>imported&gt;AromaTake</name></author>
	</entry>
</feed>