Azure Functions Triggers
A trigger is the event that causes an Azure Function to run. Every Azure Function must have exactly one trigger. Without a trigger, the function has no way to know when to start. Think of the trigger as the switch that turns the function on.
The Trigger Concept – Analogy
┌──────────────────────────────────────────────────────────────┐ │ TRIGGER ANALOGY │ │ │ │ Doorbell ──► Rings ──► Person Opens Door │ │ (Event) (Trigger) (Function Runs) │ │ │ │ HTTP Request ──► Arrives ──► Function Processes It │ │ New File ──► Uploaded ──► Function Resizes It │ │ 9:00 AM ──► Reached ──► Function Sends Report │ │ Queue Message ──► Arrives ──► Function Processes It │ └──────────────────────────────────────────────────────────────┘
Types of Triggers in Azure Functions
| Trigger Type | What Starts the Function | Common Use Case |
|---|---|---|
| HTTP Trigger | An HTTP request (GET, POST, PUT, DELETE) | REST APIs, webhooks, form submissions |
| Timer Trigger | A schedule (like a cron job) | Daily reports, cleanup jobs, reminders |
| Blob Storage Trigger | A new or updated file in Azure Blob Storage | Image resize, document processing |
| Queue Storage Trigger | A new message in Azure Storage Queue | Order processing, notification systems |
| Service Bus Trigger | A message on Azure Service Bus queue or topic | Enterprise messaging, microservices |
| Event Hub Trigger | Events from Azure Event Hubs | IoT data, real-time telemetry, logs |
| Event Grid Trigger | Events published to Azure Event Grid | React to Azure resource changes |
| Cosmos DB Trigger | Changes in an Azure Cosmos DB container | Sync data, audit logging |
How Triggers Are Defined
Triggers are configured in the function.json file using the type property. Each trigger type has its own set of required properties.
HTTP Trigger – function.json
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"name": "req",
"authLevel": "anonymous",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Timer Trigger – function.json
{
"bindings": [
{
"type": "timerTrigger",
"direction": "in",
"name": "myTimer",
"schedule": "0 0 9 * * *"
}
]
}
The schedule value uses a CRON expression. The pattern above runs the function every day at 9:00 AM.
Queue Storage Trigger – function.json
{
"bindings": [
{
"type": "queueTrigger",
"direction": "in",
"name": "myQueueItem",
"queueName": "orders",
"connection": "AzureWebJobsStorage"
}
]
}
CRON Expression Format for Timer Trigger
Azure Functions uses a 6-field CRON expression (unlike the standard 5-field Linux cron). The fields from left to right are:
{second} {minute} {hour} {day-of-month} {month} {day-of-week}
Example: 0 0 9 * * *
│ │ │ │ │ └── Every day of the week
│ │ │ └─┘ Every month, every day of month
│ │ └────────── At hour 9 (9 AM)
│ └──────────── At minute 0
└────────────── At second 0
| CRON Expression | Meaning |
|---|---|
0 0 9 * * * | Every day at 9:00 AM |
0 30 8 * * 1 | Every Monday at 8:30 AM |
0 */5 * * * * | Every 5 minutes |
0 0 0 1 * * | First day of every month at midnight |
Trigger Flow – How Data Moves Into a Function
┌──────────────────────────────────────────────────────────┐ │ TRIGGER DATA FLOW │ │ │ │ External World Azure Runtime Your Code │ │ │ │ HTTP Request ─────► httpTrigger ────► req object │ │ Queue Message ─────► queueTrigger ────► string/object │ │ Timer fires ─────► timerTrigger ────► TimerInfo obj │ │ File uploaded ─────► blobTrigger ────► Stream/byte[] │ │ │ │ The trigger wraps the event data and hands it to │ │ the function as a parameter. │ └──────────────────────────────────────────────────────────┘
Trigger vs Input Binding – What is the Difference?
This is a common point of confusion for beginners.
| Aspect | Trigger | Input Binding |
|---|---|---|
| Count per function | Exactly one | Zero or more |
| Purpose | Starts the function | Reads additional data after function starts |
| Example | HTTP request arrives → function runs | While running, read a record from Cosmos DB |
Choosing the Right Trigger
┌──────────────────────────────────────────────────────────┐ │ CHOOSING THE RIGHT TRIGGER │ │ │ │ Need to build an API endpoint? │ │ └──► HTTP Trigger │ │ │ │ Need to run a task on a schedule? │ │ └──► Timer Trigger │ │ │ │ Need to react when a file is uploaded? │ │ └──► Blob Storage Trigger │ │ │ │ Need to process items from a queue? │ │ └──► Queue Storage Trigger or Service Bus Trigger │ │ │ │ Need to process real-time event streams? │ │ └──► Event Hub Trigger │ │ │ │ Need to react when database records change? │ │ └──► Cosmos DB Trigger │ └──────────────────────────────────────────────────────────┘
Key Points to Remember
- Every Azure Function has exactly one trigger
- The trigger defines what starts the function
- Trigger configuration lives in function.json
- Each trigger passes a specific data object into the function code
- Triggers are different from bindings — bindings are covered in the next topic
