Azure Functions Bindings Metadata

Overview

Azure Functions bindings provide a declarative way to connect your function code to other Azure services and external event sources. Bindings abstract away the underlying SDKs and boilerplate code, allowing you to focus on your business logic.

Metadata for bindings is crucial for the Azure Functions runtime to understand how to configure and interact with these services. This metadata is typically defined in configuration files like function.json or through attributes in your code (for languages like C#).

Understanding binding metadata is key to effectively using Azure Functions, enabling you to:

Binding Metadata Schema

The core of binding configuration lies in defining the properties for each binding. While specific properties vary by binding type, there are common elements:

Common Binding Properties

Property Description Required
type The type of the binding (e.g., httpTrigger, blob, queue, cosmosDB). Yes
direction Specifies if the binding is for triggering the function (in), sending data out (out), or both (inout). For triggers, this is implicitly in. Yes (for non-trigger bindings)
name The name of the parameter in your function code that will be bound to this binding. Yes
connection The name of an app setting that contains the connection string for the service. No (depends on binding type)
path Used for file system based bindings (e.g., Blob storage, File shares) to specify a path pattern. No (depends on binding type)
dataType Specifies the data type (e.g., string, binary, stream, array). No (defaults often apply)

Each binding type has its own set of specific properties. For example, a queue output binding requires queueName, and a cosmosDB input binding requires databaseName, collectionName, and connectionStringSetting.

Examples

Here are a few common binding metadata configurations:

HTTP Trigger and Output Binding

This example shows an HTTP trigger that expects a name query parameter and returns a greeting via an HTTP output binding.

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

Azure Blob Storage Input and Output Bindings

This function reads a blob from a specific container and path, processes it, and then writes the result to another blob.

{
  "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"
    }
  ]
}

Azure Queue Storage Input Binding

This function is triggered by a message arriving in a specific Azure Queue.

{
  "scriptFile": "../run.csx",
  "bindings": [
    {
      "name": "queueTrigger",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "my-queue-items",
      "connection": "AzureWebJobsStorage"
    }
  ]
}