MSDN Documentation

Understanding Azure Functions Bindings

This tutorial explores the core concept of Azure Functions bindings, which allow you to declaratively connect your functions to other Azure services and external data sources without writing extensive boilerplate code.

What are Bindings?

Bindings in Azure Functions provide a way to integrate with Azure services and other resources. They abstract away the complexities of connecting to services, allowing you to focus on your function's core logic. You define bindings in your function's configuration, specifying the type of binding, its direction (input or output), and any necessary connection details.

Types of Bindings

Azure Functions supports a wide range of bindings, categorized as:

Common Binding Examples

HTTP Trigger Binding

This is one of the most common triggers. It allows your function to be invoked via an HTTP request. It also acts as an output binding for returning HTTP responses.

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

Blob Storage Binding

Easily read from or write to Azure Blob Storage. You can specify the container, blob name, and connection string.

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

Queue Storage Binding

Process messages from an Azure Storage Queue or send messages to a queue.

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "message",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputQueueItem",
      "type": "queue",
      "direction": "out",
      "queueName": "myqueue-processed",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

How Bindings Work

When you define bindings in your function.json (or through attributes in other languages), the Azure Functions runtime handles the connection and data marshaling. For input bindings, the data is passed as arguments to your function. For output bindings, you return a value or assign it to a specific output parameter, and the runtime takes care of sending it to the destination.

Configuring Bindings

Bindings are configured in the function.json file located in your function's directory. Each binding entry describes:

Benefits of Using Bindings

Further Reading