Triggers
Triggers define how an Azure Function is executed. They provide a way to invoke a function based on events from Azure services or external sources. Each trigger has specific configuration options and data payloads.
Common Trigger Types
- HTTP Trigger: Invokes a function via an HTTP request. Ideal for building web APIs and webhooks.
- Timer Trigger: Executes a function on a schedule defined by a cron expression or a recurrence interval. Useful for background tasks and scheduled jobs.
- Blob Trigger: Executes a function when a new or updated blob is detected in Azure Blob Storage. Perfect for processing file uploads or changes.
- Queue Trigger: Invokes a function when a message is added to an Azure Storage Queue. Suitable for decoupling services and processing work items.
- Event Grid Trigger: Responds to events published by Azure Event Grid. Enables event-driven architectures and integration with a wide range of Azure services.
- Service Bus Trigger: Processes messages from Azure Service Bus Queues or Topics. Offers advanced messaging capabilities like sessions and dead-lettering.
Trigger Configuration
The configuration of a trigger depends on its type. This typically involves specifying connection strings, paths, queue names, topics, or schedules.
For example, an HTTP trigger can be configured with different HTTP methods (GET, POST, etc.) and authorization levels. A Timer trigger requires a schedule property, usually in CRON format.
Example: HTTP Trigger Configuration (function.json)
{
  "scriptFile": "index.js",
  "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": "index.js",
  "bindings": [
    {
      "type": "timerTrigger",
      "direction": "in",
      "name": "myTimer",
      "schedule": "0 */5 * * * *"
    }
  ]
}
            Trigger Data
When a trigger invokes a function, it passes data related to the event. The format and content of this data are specific to each trigger type.
- HTTP Trigger: Provides the incoming HTTP request object, including headers, query parameters, and the request body.
- Blob Trigger: Provides information about the changed blob, such as its name, size, and content.
- Queue Trigger: Provides the message content from the queue.
You can find detailed reference documentation for each trigger type in the Azure Functions documentation. For more information, see the complete guide to Azure Functions triggers.