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 TypeWhat Starts the FunctionCommon Use Case
HTTP TriggerAn HTTP request (GET, POST, PUT, DELETE)REST APIs, webhooks, form submissions
Timer TriggerA schedule (like a cron job)Daily reports, cleanup jobs, reminders
Blob Storage TriggerA new or updated file in Azure Blob StorageImage resize, document processing
Queue Storage TriggerA new message in Azure Storage QueueOrder processing, notification systems
Service Bus TriggerA message on Azure Service Bus queue or topicEnterprise messaging, microservices
Event Hub TriggerEvents from Azure Event HubsIoT data, real-time telemetry, logs
Event Grid TriggerEvents published to Azure Event GridReact to Azure resource changes
Cosmos DB TriggerChanges in an Azure Cosmos DB containerSync 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 ExpressionMeaning
0 0 9 * * *Every day at 9:00 AM
0 30 8 * * 1Every 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.

AspectTriggerInput Binding
Count per functionExactly oneZero or more
PurposeStarts the functionReads additional data after function starts
ExampleHTTP request arrives → function runsWhile 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

Leave a Comment