Azure Functions 简介An introduction to Azure Functions

Azure Functions 是用于在云中轻松运行小段代码或“函数”的一个解决方案。Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. 用户可以只编写解决现有问题所需的代码,而无需担心要运行该代码的整个应用程序或基础结构。You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Functions 可使开发更有效率,并可以使用自己所选的开发语言,例如 C#、Java、JavaScript 和 PowerShell。Functions can make development even more productive, and you can use your development language of choice, such as C#, Java, JavaScript, and PowerShell. 只需为代码运行的时间付费,并可信任 Azure 会根据需要进行调整。Pay only for the time your code runs and trust Azure to scale as needed. 使用 Azure Functions 可以在 Azure 上开发无服务器应用程序。Azure Functions lets you develop serverless applications on Azure.

本主题提供有关 Azure Functions 的高级概述。This topic provides a high-level overview of Azure Functions. 如果要立即投入和开始使用 Functions,请从创建第一个 Azure 函数开始。If you want to jump right in and get started with Functions, start with Create your first Azure Function. 如果要查找有关 Functions 的更多技术信息,请参阅 开发人员参考If you are looking for more technical information about Functions, see the developer reference.


下面是 Functions 的一些主要功能:Here are some key features of Functions:

  • 语言选择 - 使用所选的 C#、Java、Javascript 和其他语言编写函数。Choice of language - Write functions using your choice of C#, Java, Javascript, and other languages. 有关完整列表,请参阅支持的语言See Supported languages for the complete list.
  • 按使用付费定价模型 - 仅为运行代码所用的时间付费。Pay-per-use pricing model - Pay only for the time spent running your code. 请参阅定价部分中的使用托管计划选项。See the Consumption hosting plan option in the pricing section.
  • 引入自己的依赖项 - Functions 支持 NuGet 和 NPM,因此用户可以使用自己的常用库。Bring your own dependencies - Functions supports NuGet and NPM, so you can use your favorite libraries.
  • 集成安全性 - 使用 OAuth 提供程序(如 Azure Active Directory 和 Microsoft 帐户)保护 HTTP 触发的函数。Integrated security - Protect HTTP-triggered functions with OAuth providers such as Azure Active Directory and Microsoft Account.
  • 简化集成 - 轻松利用 Azure 服务和软件即服务 (SaaS) 产品/服务。Simplified integration - Easily leverage Azure services and software-as-a-service (SaaS) offerings. 有关一些示例,请参阅集成部分See the integrations section for some examples.
  • 灵活开发 - 直接在门户中编写函数代码,或者通过 GitHub 和其他受支持的开发工具设置持续集成和部署代码。Flexible development - Code your functions right in the portal or set up continuous integration and deploy your code through GitHub and other supported development tools.
  • 开放源代码 - Functions 运行时是一个开放源代码, 可在 GitHub 上找到Open-source - The Functions runtime is open-source and available on GitHub.

使用 Functions 可以做什么?What can I do with Functions?

Functions 是一个理想的解决方案,用于处理数据、集成系统、使用物联网 (IoT) 以及生成简单的 API 和微服务。Functions is a great solution for processing data, integrating systems, working with the internet-of-things (IoT), and building simple APIs and microservices. 对于以下任务请考虑使用 Functions:例如,图像或订单处理、文件维护,或者要按计划运行的任何任务。Consider Functions for tasks like image or order processing, file maintenance, or for any tasks that you want to run on a schedule.

Functions 提供模板,以帮助用户从主要方案开始,包括以下模板:Functions provides templates to get you started with key scenarios, including the following:

  • HTTPTrigger - 使用 HTTP 请求触发执行代码。HTTPTrigger - Trigger the execution of your code by using an HTTP request. 有关示例,请参阅创建第一个函数For an example, see Create your first function.
  • TimerTrigger - 按预定义的计划执行清除或其他批处理任务。TimerTrigger - Execute cleanup or other batch tasks on a predefined schedule. 有关示例,请参阅创建由计时器触发的函数For an example, see Create a function triggered by a timer.
  • CosmosDBTrigger - 在 NoSQL 数据库中以集合形式添加或更新 Azure Cosmos DB 文档时,对这些文档进行处理。CosmosDBTrigger - Process Azure Cosmos DB documents when they are added or updated in collections in a NoSQL database. 有关详细信息,请参阅 Azure Cosmos DB 绑定For more information, see Azure Cosmos DB bindings.
  • BlobTrigger - Azure 存储 blob 添加到容器时,处理这些 blob。BlobTrigger - Process Azure Storage blobs when they are added to containers. 可以使用此函数调整图像大小。You might use this function for image resizing. 有关详细信息,请参阅 Blob 存储帐户绑定For more information, see Blob storage bindings.
  • QueueTrigger - 当消息到达 Azure 存储队列时,响应这些消息。QueueTrigger - Respond to messages as they arrive in an Azure Storage queue. 有关详细信息,请参阅 Azure 队列存储绑定For more information, see Azure Queue storage bindings.
  • EventHubTrigger - 响应传送到 Azure 事件中心的事件。EventHubTrigger - Respond to events delivered to an Azure Event Hub. 在应用程序检测、用户体验或工作流处理以及物联网 (IoT) 方案中特别有用。Particularly useful in application instrumentation, user experience or workflow processing, and internet-of-things (IoT) scenarios. 有关详细信息,请参阅事件中心绑定For more information, see Event Hubs bindings.
  • ServiceBusQueueTrigger - 通过侦听消息队列将代码连接到其他 Azure 服务或本地服务。ServiceBusQueueTrigger - Connect your code to other Azure services or on-premises services by listening to message queues. 有关详细信息,请参阅服务总线绑定For more information, see Service Bus bindings.
  • ServiceBusTopicTrigger - 通过订阅主题将代码连接到其他 Azure 服务或本地服务。ServiceBusTopicTrigger - Connect your code to other Azure services or on-premises services by subscribing to topics. 有关详细信息,请参阅服务总线绑定For more information, see Service Bus bindings.

Azure Functions 支持 触发器(用于启动代码执行)和绑定(用于简化针对输入和输出数据进行的编码)。Azure Functions supports triggers, which are ways to start execution of your code, and bindings, which are ways to simplify coding for input and output data. 有关 Azure Functions 提供的触发器和绑定的详细说明,请参阅 Azure Functions 触发器和绑定开发人员参考For a detailed description of the triggers and bindings that Azure Functions provides, see Azure Functions triggers and bindings developer reference.


Azure Functions 可与各种 Azure 和第三方服务集成。Azure Functions integrates with various Azure and 3rd-party services. 这些服务可以触发函数开始执行,或者可用作代码的输入和输出。These services can trigger your function and start execution, or they can serve as input and output for your code. Azure Functions 支持以下服务集成:The following service integrations are supported by Azure Functions:

  • Azure Cosmos DBAzure Cosmos DB
  • Azure 事件中心Azure Event Hubs
  • Azure 通知中心Azure Notification Hubs
  • Azure 服务总线(队列和主题)Azure Service Bus (queues and topics)
  • Azure 存储(blob、队列和表)Azure Storage (blob, queues, and tables)
  • 本地(使用服务总线)On-premises (using Service Bus)

Functions 的费用是多少?How much does Functions cost?

Azure Functions 有两种定价计划。Azure Functions has two kinds of pricing plans. 请选择最适合自己的那种:Choose the one that best fits your needs:

  • 使用计划 - 用户的函数运行时,Azure 提供所有所需的计算资源。Consumption plan - When your function runs, Azure provides all of the necessary computational resources. 用户不必担心资源管理,只需为自己的代码运行的时间付费。You don't have to worry about resource management, and you only pay for the time that your code runs.
  • 应用服务计划 - 将函数像 Web 应用一样运行。App Service plan - Run your functions just like your web apps. 如果已对其他应用程序使用应用服务,可以按相同的计划运行自己的函数,而不用另外付费。When you are already using App Service for your other applications, you can run your functions on the same plan at no additional cost.

有关托管计划的详细信息,请参阅 Azure Functions 托管计划比较For more information about hosting plans, see Azure Functions hosting plan comparison. 完整的定价详细信息可在 Functions 定价页中找到。Full pricing details are available on the Functions Pricing page.

后续步骤Next Steps