Azure Functions triggers and bindings reference
Last updated: October 26, 2023
This article provides a reference for triggers and bindings for Azure Functions.
What are triggers and bindings?
Azure Functions uses triggers and bindings to enable event-driven programming. A trigger defines how a function is invoked, and a binding allows you to declaratively connect to other Azure services and to publically available REST APIs without explicitly writing service client code.
Supported Triggers and Bindings
Azure Functions supports a rich set of triggers and bindings that allow you to integrate with various Azure services and external data sources. The following table lists the most common triggers and bindings:
Type | Description | Category |
---|---|---|
Blob Storage trigger | Trigger a function when a new or updated blob is detected in Blob Storage. | Storage |
Cosmos DB trigger | Trigger a function when a new or updated document is available in a Cosmos DB collection. | Data |
Event Grid trigger | Trigger a function in response to events published to Azure Event Grid. | Eventing |
Event Hubs trigger | Trigger a function when new events are available in an Event Hubs stream. | Messaging |
HTTP trigger | Trigger a function when an HTTP request is received. Can also be used for output bindings to send HTTP responses. | API |
Queue Storage trigger | Trigger a function when a new message is available in a Queue Storage queue. | Storage |
Service Bus trigger | Trigger a function when a new message is available in a Service Bus queue or topic. | Messaging |
Timer trigger | Trigger a function on a schedule defined by a cron expression. | Scheduling |
Blob Storage output binding | Write a blob to Blob Storage. | Storage |
Cosmos DB output binding | Write documents to a Cosmos DB collection. | Data |
Event Hubs output binding | Write events to an Event Hubs stream. | Messaging |
Queue Storage output binding | Add a message to a Queue Storage queue. | Storage |
Service Bus output binding | Send messages to a Service Bus queue or topic. | Messaging |
How to use triggers and bindings
Triggers and bindings are configured in the function.json
file for your function. Here's an example of an HTTP trigger and a Blob output binding:
{
"scriptFile": "run.cs",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "blob",
"direction": "out",
"name": "outputBlob",
"path": "output-container/{rand-guid}.txt",
"connection": "AzureWebJobsStorage"
}
]
}
In this example:
- The
httpTrigger
binding defines the HTTP endpoint that starts the function. - The
http
binding defines the HTTP response. - The
blob
binding defines an output binding that writes to a Blob Storage container namedoutput-container
. The filename is dynamically generated.
Important: The specific configuration details for each trigger and binding can vary. Refer to the individual binding documentation for complete information.
Developing with Triggers and Bindings
You can develop Azure Functions using various languages, including C#, JavaScript, Python, Java, and PowerShell. The SDKs and libraries abstract away the complexity of interacting with Azure services, allowing you to focus on your business logic.
Common Scenarios
- Processing data changes: Use Blob or Cosmos DB triggers to react to data modifications.
- Responding to events: Leverage Event Grid or Event Hubs triggers for real-time event processing.
- Scheduled tasks: Implement timer triggers for recurring jobs.
- API development: Use HTTP triggers and bindings to build serverless APIs.