Azure Functions Beginner

Triggers and bindings

Triggers start a function and bindings connect it to other services without writing client code. Together they are what makes functions short: the plumbing is declared with attributes and the method holds only your logic.

Trigger in, bindings out
  1. StartTriggerBlob uploaded to uploads/photo.jpg.
  2. Step 2Input binding (optional)Load a settings document from Cosmos DB.
  3. Step 3Function codeCreate the thumbnail.
  4. EndOutput bindingWrite a message to the thumbnails queue.

Attributes declare the plumbing; the method contains only the logic.

Trigger: what starts the function

Every function has exactly one trigger. The trigger attribute says what to listen to and passes the event data into the method as a parameter: the HTTP request, the queue message text, the blob contents, or timer information.

Common triggers are HTTP, Timer, Azure Storage Queue, Service Bus, Blob, Event Grid, Event Hubs and Cosmos DB.

Bindings: reading and writing data

Input bindings load data for you, and output bindings send data when the function finishes. In the isolated worker, output bindings are attributes on the return value or on properties of a returned class.

C#
public class ResizeImage
{
    // Trigger: a new blob in "uploads". Output: a message on the "thumbnails" queue.
    [Function("ResizeImage")]
    [QueueOutput("thumbnails", Connection = "Storage")]
    public string Run(
        [BlobTrigger("uploads/{name}", Connection = "Storage")] byte[] image,
        string name)
    {
        // ... create the thumbnail ...
        return name; // becomes the queue message
    }
}

Connections and settings

The Connection property names an app setting, not the secret itself. Connection = "Storage" makes the runtime read the setting called Storage, or identity-based settings such as Storage__queueServiceUri when you use a managed identity.

Values in %percent% signs are also read from settings, so queue and container names can change per environment: [QueueTrigger("%OrdersQueue%")].

When to skip bindings

  • Bindings are great for simple reads and writes.
  • For complex work, such as transactions, queries with many conditions or batching, inject the normal SDK client (BlobServiceClient, ServiceBusClient, CosmosClient) and call it yourself.
  • Mixing both is normal: trigger with a binding, then use SDK clients inside.

Interview question

What is the difference between a trigger and a binding in Azure Functions?

A trigger is what starts the function, and each function has exactly one, such as HTTP, timer or a queue message. Bindings are declarative connections to other services: input bindings read data and output bindings write data, so you do not write client code for simple cases. A function can have many bindings or none.

Your progress is saved only in this browser.

Want the full details? Read the official Microsoft documentation for this topic.