Azure Functions Triggers
Triggers define how a function is invoked. When a trigger event occurs, the Azure Functions host automatically runs your function. Triggers have a fixed set of parameters that are passed to your function, and they can be configured to bind to specific resources.
Common Trigger Types
Azure Functions supports a wide variety of triggers, allowing you to integrate with numerous Azure services and third-party event sources. Here are some of the most commonly used triggers:
- HTTP Trigger: Invokes a function when an HTTP request is received. This is ideal for building web APIs and webhooks.
- Timer Trigger: Invokes a function on a schedule defined by a CRON expression. Useful for scheduled tasks and batch processing.
- Blob Trigger: Invokes a function when a new or updated blob is detected in Azure Blob Storage.
- Queue Trigger: Invokes a function when a message arrives in an Azure Storage Queue.
- Event Grid Trigger: Invokes a function in response to events published to Azure Event Grid.
- Cosmos DB Trigger: Invokes a function when changes are detected in a Cosmos DB collection.
- Service Bus Trigger: Invokes a function when a message arrives in an Azure Service Bus queue or topic.
Trigger Configuration
Triggers are configured in your function's function.json file or using attributes in your code (for in-process models). The configuration typically includes:
- Type: The type of trigger (e.g.,
httpTrigger,timerTrigger,blobTrigger). - Direction: Set to
infor triggers. - Name: The name of the parameter that will receive the trigger payload in your function code.
- Provider-specific settings: These vary by trigger type and can include things like queue names, blob paths, or HTTP methods.
Example: HTTP Trigger Configuration (function.json)
{
"scriptFile": "run.cs",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Example: Timer Trigger Configuration (function.json)
{
"scriptFile": "run.cs",
"bindings": [
{
"type": "timerTrigger",
"direction": "in",
"name": "myTimer",
"schedule": "0 */5 * * * *"
}
]
}
Trigger Parameters
The parameters available to your function depend on the trigger type. For example, an HTTP trigger often provides an HTTP request object, while a blob trigger provides information about the blob that was created or updated.
API Reference for Triggers
The following table outlines the key properties for some common trigger types. Refer to the official Azure Functions documentation for a comprehensive list and detailed information.
| Trigger Type | Key Properties | Description |
|---|---|---|
| HTTP | methods, authLevel |
Defines allowed HTTP methods and authentication level for requests. |
| Timer | schedule |
A CRON expression defining the execution schedule. |
| Blob | path, connection |
The blob path to monitor and the storage account connection string. |
| Queue | queueName, connection |
The name of the storage queue and the connection string. |
| Event Grid | topicEndpointHostNames, subscriptionName |
Endpoint for Event Grid topic and the name for the subscription. |
Learn More
For in-depth details and advanced configurations for each trigger type, please consult the official Azure Functions documentation on triggers and bindings.