使用绑定将函数连接到 Azure 服务Connect functions to Azure services using bindings

创建函数时,请将特定于语言的触发器代码从一组触发器模板添加到项目中。When you create a function, language-specific trigger code is added in your project from a set of trigger templates. 若要使用输入或输出绑定将函数连接到其他服务,则必须在函数中添加特定的绑定定义。If you want to connect your function to other services by using input or output bindings, you have to add specific binding definitions in your function. 有关绑定的详细信息,请参阅 Azure Functions 触发器和绑定的概念To learn more about bindings, see Azure Functions triggers and bindings concepts.

本地开发Local development

在本地开发函数时,需要更新函数代码以添加绑定。When you develop functions locally, you need to update the function code to add bindings. 使用 Visual Studio Code 可以更轻松地将绑定添加到函数。Using Visual Studio Code can make it easier to add bindings to a function.

Visual Studio CodeVisual Studio Code

使用 Visual Studio Code 开发函数且函数使用 function.json 文件时,Azure Functions 扩展可自动将绑定添加到现有 function.json 文件。When you use Visual Studio Code to develop your function and your function uses a function.json file, the Azure Functions extension can automatically add a binding to an existing function.json file. 若要了解详细信息,请参阅添加输入和输出绑定To learn more, see Add input and output bindings.

根据示例手动添加绑定Manually add bindings based on examples

向现有函数添加绑定时,需要同时更新函数代码和 function.json 配置文件(如果语言使用它)。When adding a binding to an existing function, you'll need update both the function code and the function.json configuration file, if used by your language. .NET 类库和 Java 函数都使用属性而不是 function.json,因此你需要改为更新属性。Both .NET class library and Java functions use attributes instead of function.json, so you'll need to update that instead.

使用下表查找特定绑定类型的示例,这些示例可用来指导你更新现有函数。Use the following table to find examples of specific binding types that you can use to guide you in updating an existing function. 首先,选择与你的项目相对应的语言选项卡。First, choose the language tab that corresponds to your project.

服务Service 示例Examples 示例Samples
Blob 存储Blob storage 触发器Trigger
输入Input
输出Output
链接Link
Azure Cosmos DBAzure Cosmos DB 触发器Trigger
输入Input
输出Output
链接Link
事件网格Event Grid 触发器Trigger
输出Output
链接Link
事件中心Event Hubs 触发器Trigger
输出Output
IoT 中心IoT Hub 触发器Trigger
输出Output
HTTPHTTP 触发器Trigger 链接Link
队列存储Queue storage 触发器Trigger
输出Output
链接Link
RabbitMQRabbitMQ 触发器Trigger
输出Output
SendGridSendGrid 输出Output
服务总线Service Bus 触发器Trigger
输出Output
链接Link
SignalRSignalR 触发器Trigger
输入Input
输出Output
表存储Table storage 输入Input
输出Output
TimerTimer 触发器Trigger 链接Link

Azure 门户Azure portal

Azure 门户中开发函数时,可以在给定函数的“集成”选项卡中添加输入和输出绑定。When you develop your functions in the Azure portal, you add input and output bindings in the Integrate tab for a given function. 新绑定将添加到 function.json 文件或方法属性,具体取决于你的语言。The new bindings are added to either the function.json file or to the method attributes, depending on your language. 以下文章显示的示例介绍了如何在门户中向现有函数添加绑定:The following articles show examples of how to add bindings to an existing function in the portal:

后续步骤Next steps