Azure Functions Triggers Overview

Triggers are how you invoke an Azure Function. A trigger defines how a function is initiated. Each function must have exactly one trigger. Triggers can be based on a schedule, an event from another Azure service, or an HTTP request.

Common Trigger Types

Azure Functions supports a wide variety of triggers, allowing your functions to respond to numerous events. Here are some of the most commonly used trigger types:

Trigger Type Description Example Use Case
HTTP Trigger Executes when an HTTP request is received. Provides a webhook-like capability. Building REST APIs, webhooks for external services.
Timer Trigger Executes on a schedule defined by a CRON expression. Scheduled tasks, recurring data processing.
Blob Storage Trigger Executes when a blob is added, updated, or deleted in Azure Blob Storage. Image processing upon upload, data transformation for new files.
Queue Storage Trigger Executes when a message is added to an Azure Storage Queue. Processing messages from a work queue, background task execution.
Service Bus Trigger Executes when a message arrives in an Azure Service Bus Queue or Topic. Handling critical messages, reliable message processing.
Event Grid Trigger Executes in response to Azure Event Grid events. Responding to resource changes, orchestrating events across services.
Cosmos DB Trigger Executes when documents are added or updated in an Azure Cosmos DB collection. Real-time data processing, event sourcing.

Trigger Configuration

Triggers are configured in the function.json file (or via attributes in code for languages like C#). The configuration specifies the type of trigger, the direction (in for triggers), and the connection details.

Example: HTTP Trigger Configuration

{
  "scriptFile": "../run.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

Example: Timer Trigger Configuration

{
  "scriptFile": "../run.py",
  "bindings": [
    {
      "type": "timerTrigger",
      "direction": "in",
      "name": "myTimer",
      "schedule": "0 */5 * * * *"
    }
  ]
}

Key Concepts

Note: The exact configuration properties for each trigger type can vary. Refer to the specific trigger documentation for detailed options and requirements.