Azure Functions Binding Reference

This reference documentation provides details about the various triggers and bindings available for Azure Functions. Bindings allow you to declaratively connect your function to other Azure services and external data sources.

Core Concepts

Azure Functions uses a declarative binding model. You define inputs and outputs for your functions in the function.json file (or via attributes in code). This model simplifies your code by abstracting away the complexities of connecting to services.

Input and Output Bindings

Bindings can be categorized as:

Supported Bindings

Below is a list of commonly used bindings. For a comprehensive list and detailed configurations, please refer to the specific service documentation.

Binding Type Description Common Use Cases
HTTP Trigger/Output Handles incoming HTTP requests and allows returning HTTP responses. Web APIs, webhook endpoints.
Timer Trigger Runs your function on a schedule defined by a CRON expression. Scheduled tasks, recurring jobs.
Blob Storage Input/Output Read from or write to Azure Blob Storage. Processing file uploads, generating reports.
Queue Storage Input/Output Read from or write to Azure Queue Storage. Decoupling services, message processing.
Cosmos DB Input/Output Interact with Azure Cosmos DB. Data persistence, real-time data retrieval.
Service Bus Input/Output Integrate with Azure Service Bus queues and topics. Enterprise messaging patterns, reliable communication.
Event Grid Trigger React to events published by Azure Event Grid. Event-driven architectures, reacting to resource changes.
Event Hubs Trigger/Output Process events from Azure Event Hubs. Real-time data streaming, telemetry processing.

HTTP Trigger and Output Bindings

The HTTP trigger starts your function in response to an HTTP request. The HTTP output binding allows your function to return an HTTP response.

Example: Simple HTTP API

function.json

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

run.csx (C# example)

using System.Net;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.Rpc;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

public static class HttpExample
{
    [FunctionName("HttpExample")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string name = req.Query["name"];
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        string personName = data?.name ?? name;

        string responseMessage = string.IsNullOrEmpty(personName)
            ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
            : $"Hello, {personName}!";

        return new OkObjectResult(responseMessage);
    }
}

Configuration Properties:

Timer Trigger

The Timer trigger executes your function based on a schedule.

Example: Scheduled Task

function.json

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

run.csx (C# example)

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class TimerExample
{
    [FunctionName("TimerExample")]
    public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.UtcNow}");
    }
}

Configuration Properties:

Blob Storage Bindings

Interact with Azure Blob Storage for reading and writing data.

Example: Blob Input and Output

function.json

{
  "scriptFile": "run.csx",
  "bindings": [
    {
      "name": "inputBlob",
      "type": "blob",
      "direction": "in",
      "path": "samples-workitems/{name}.txt",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputBlob",
      "type": "blob",
      "direction": "out",
      "path": "samples-output/{name}.txt",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

run.csx (C# example)

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class BlobExample
{
    [FunctionName("BlobExample")]
    public static void Run(
        [BlobTrigger("samples-workitems/{name}.txt")] string inputBlob,
        [Blob("samples-output/{name}.txt", FileAccess.Write)] out string outputBlob,
        ILogger log)
    {
        log.LogInformation($"Blob input content: {inputBlob}");
        outputBlob = $"Processed: {inputBlob.ToUpper()}";
        log.LogInformation("Blob processed and output created.");
    }
}

Configuration Properties:

Further Reading

Note: The specific configuration and usage details for each binding can vary. Always refer to the official Microsoft Azure documentation for the most up-to-date information.