Azure Functions triggers and bindings concepts
In this article, you learn the high-level concepts surrounding functions triggers and bindings.
Triggers cause a function to run. A trigger defines how a function is invoked and a function must have exactly one trigger. Triggers have associated data, which is often provided as the payload of the function.
Binding to a function is a way of declaratively connecting another resource to the function; bindings may be connected as input bindings, output bindings, or both. Data from bindings is provided to the function as parameters.
You can mix and match different bindings to suit your needs. Bindings are optional and a function might have one or multiple input and/or output bindings.
Triggers and bindings let you avoid hardcoding access to other services. Your function receives data (for example, the content of a queue message) in function parameters. You send data (for example, to create a queue message) by using the return value of the function.
Consider the following examples of how you could implement different functions.
Example scenario | Trigger | Input binding | Output binding |
---|---|---|---|
A new queue message arrives which runs a function to write to another queue. | Queue* | None | Queue* |
A scheduled job reads Blob Storage contents and creates a new Azure Cosmos DB document. | Timer | Blob Storage | Azure Cosmos DB |
The Event Grid is used to read an image from Blob Storage and a document from Azure Cosmos DB to send an email. | Event Grid | Blob Storage and Azure Cosmos DB | SendGrid |
A webhook that uses Microsoft Graph to update an Excel sheet. | HTTP | None | Microsoft Graph |
* Represents different queues
These examples aren't meant to be exhaustive, but are provided to illustrate how you can use triggers and bindings together.
Trigger and binding definitions
Triggers and bindings are defined differently depending on the development language.
Language | Triggers and bindings are configured by... |
---|---|
C# class library | decorating methods and parameters with C# attributes |
Java | decorating methods and parameters with Java annotations |
JavaScript/PowerShell/Python/TypeScript | updating function.json (schema) |
For languages that rely on function.json, the portal provides a UI for adding bindings in the Integration tab. You can also edit the file directly in the portal in the Code + test tab of your function. Visual Studio Code lets you easily add a binding to a function.json file by following a convenient set of prompts.
In .NET and Java, the parameter type defines the data type for input data. For instance, use string
to bind to the text of a queue trigger, a byte array to read as binary, and a custom type to de-serialize to an object. Since .NET class library functions and Java functions don't rely on function.json for binding definitions, they can't be created and edited in the portal. C# portal editing is based on C# script, which uses function.json instead of attributes.
To learn more about how to add bindings to existing functions, see Connect functions to Azure services using bindings.
For languages that are dynamically typed such as JavaScript, use the dataType
property in the function.json file. For example, to read the content of an HTTP request in binary format, set dataType
to binary
:
{
"dataType": "binary",
"type": "httpTrigger",
"name": "req",
"direction": "in"
}
Other options for dataType
are stream
and string
.
Binding direction
All triggers and bindings have a direction
property in the function.json file:
- For triggers, the direction is always
in
- Input and output bindings use
in
andout
- Some bindings support a special direction
inout
. If you useinout
, only the Advanced editor is available via the Integrate tab in the portal.
When you use attributes in a class library to configure triggers and bindings, the direction is provided in an attribute constructor or inferred from the parameter type.
Add bindings to a function
You can connect your function to other services by using input or output bindings. Add a binding by adding its specific definitions to your function. To learn how, see Add bindings to an existing function in Azure Functions.
Supported bindings
This table shows the bindings that are supported in the major versions of the Azure Functions runtime:
Type | 1.x1 | 2.x and higher2 | Trigger | Input | Output |
---|---|---|---|---|---|
Blob storage | ✔ | ✔ | ✔ | ✔ | ✔ |
Azure Cosmos DB | ✔ | ✔ | ✔ | ✔ | ✔ |
Azure Data Explorer | ✔ | ✔ | ✔ | ||
Azure SQL | ✔ | ✔ | ✔ | ✔ | |
Dapr4 | ✔ | ✔ | ✔ | ✔ | |
Event Grid | ✔ | ✔ | ✔ | ✔ | |
Event Hubs | ✔ | ✔ | ✔ | ✔ | |
HTTP & webhooks | ✔ | ✔ | ✔ | ✔ | |
IoT Hub | ✔ | ✔ | ✔ | ||
Kafka3 | ✔ | ✔ | ✔ | ||
Mobile Apps | ✔ | ✔ | ✔ | ||
Notification Hubs | ✔ | ✔ | |||
Queue storage | ✔ | ✔ | ✔ | ✔ | |
Redis | ✔ | ✔ | |||
RabbitMQ3 | ✔ | ✔ | ✔ | ||
SendGrid | ✔ | ✔ | ✔ | ||
Service Bus | ✔ | ✔ | ✔ | ✔ | |
SignalR | ✔ | ✔ | ✔ | ✔ | |
Table storage | ✔ | ✔ | ✔ | ✔ | |
Timer | ✔ | ✔ | ✔ | ||
Twilio | ✔ | ✔ | ✔ |
1 Support will end for version 1.x of the Azure Functions runtime on September 14, 2026. We highly recommend that you migrate your apps to version 4.x for full support.
2 Starting with the version 2.x runtime, all bindings except HTTP and Timer must be registered. See Register binding extensions.
3 Triggers aren't supported in the Consumption plan. Requires runtime-driven triggers.
4 Supported only in Kubernetes, IoT Edge, and other self-hosted modes only.
For information about which bindings are in preview or are approved for production use, see Supported languages.
Specific binding extension versions are only supported while the underlying service SDK is supported. Changes to support in the underlying service SDK version affect the support for the consuming extension.
Bindings code examples
Use the following table to find examples of specific binding types that show you how to work with bindings in your functions. First, choose the language tab that corresponds to your project.
Binding code for C# depends on the specific process model.
Service | Examples | Samples |
---|---|---|
Blob storage | Trigger Input Output |
Link |
Azure Cosmos DB | Trigger Input Output |
Link |
Azure Data Explorer | Input Output |
Link |
Azure SQL | Trigger Input Output |
Link |
Event Grid | Trigger Output |
Link |
Event Hubs | Trigger Output |
|
IoT Hub | Trigger Output |
|
HTTP | Trigger | Link |
Queue storage | Trigger Output |
Link |
RabbitMQ | Trigger Output |
|
SendGrid | Output | |
Service Bus | Trigger Output |
Link |
SignalR | Trigger Input Output |
|
Table storage | Input Output |
|
Timer | Trigger | Link |
Twilio | Output | Link |
Service | Examples | Samples |
---|---|---|
Blob storage | Trigger Input Output |
Link |
Azure Cosmos DB | Trigger Input Output |
Link |
Azure Data Explorer | Input Output |
Link |
Azure SQL | Trigger Input Output |
|
Event Grid | Trigger Output |
Link |
Event Hubs | Trigger Output |
|
IoT Hub | Trigger Output |
|
HTTP | Trigger | Link |
Queue storage | Trigger Output |
Link |
RabbitMQ | Trigger Output |
|
SendGrid | Output | |
Service Bus | Trigger Output |
Link |
SignalR | Trigger Input Output |
|
Table storage | Input Output |
|
Timer | Trigger | Link |
Twilio | Output | Link |
Service | Examples | Samples |
---|---|---|
Blob storage | Trigger Input Output |
Link |
Azure Cosmos DB | Trigger Input Output |
Link |
Azure Data Explorer | Input Output |
|
Azure SQL | Trigger Input Output |
Link |
Event Grid | Trigger Output |
Link |
Event Hubs | Trigger Output |
|
IoT Hub | Trigger Output |
|
HTTP | Trigger | Link |
Queue storage | Trigger Output |
Link |
RabbitMQ | Trigger Output |
|
SendGrid | Output | |
Service Bus | Trigger Output |
Link |
SignalR | Trigger Input Output |
|
Table storage | Input Output |
|
Timer | Trigger | Link |
Twilio | Output | Link |
Service | Examples | Samples |
---|---|---|
Blob storage | Trigger Input Output |
Link |
Azure Cosmos DB | Trigger Input Output |
Link |
Azure SQL | Trigger Input Output |
|
Event Grid | Trigger Output |
Link |
Event Hubs | Trigger Output |
|
IoT Hub | Trigger Output |
|
HTTP | Trigger | Link |
Queue storage | Trigger Output |
Link |
RabbitMQ | Trigger Output |
|
SendGrid | Output | |
Service Bus | Trigger Output |
Link |
SignalR | Trigger Input Output |
|
Table storage | Input Output |
|
Timer | Trigger | Link |
Twilio | Output | Link |
Binding code for Python depends on the Python model version.
Service | Examples | Samples |
---|---|---|
Blob storage | Trigger Input Output |
Link |
Azure Cosmos DB | Trigger Input Output |
Link |
Azure Data Explorer | Input Output |
|
Azure SQL | Trigger Input Output |
Link |
Event Grid | Trigger Output |
Link |
Event Hubs | Trigger Output |
|
IoT Hub | Trigger Output |
|
HTTP | Trigger | Link |
Queue storage | Trigger Output |
Link |
RabbitMQ | Trigger Output |
|
SendGrid | Output | |
Service Bus | Trigger Output |
Link |
SignalR | Trigger Input Output |
|
Table storage | Input Output |
|
Timer | Trigger | Link |
Twilio | Output | Link |
Custom bindings
You can create custom input and output bindings. Bindings must be authored in .NET, but can be consumed from any supported language. For more information about creating custom bindings, see Creating custom input and output bindings.
Resources
- Binding expressions and patterns
- Using the Azure Function return value
- How to register a binding expression
- Testing:
- Handling binding errors
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for