Azure Functions Bindings Configuration

This document provides a comprehensive guide to configuring bindings in Azure Functions. Bindings offer a declarative way to connect your function to other Azure services and data sources, simplifying your code by abstracting away complex connection logic.

Core Concepts

Bindings are defined in your function's configuration file, typically function.json. Each binding has a specific type, direction (in, out, or inout), and a set of properties that define how it interacts with the service it's connected to.

Binding Properties

Common properties include:

function.json Structure

A typical function.json file looks like this:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "blob",
      "direction": "in",
      "name": "inputBlob",
      "path": "samples-workitems/{name}.txt",
      "connection": "AzureWebJobsStorage"
    },
    {
      "type": "blob",
      "direction": "out",
      "name": "outputBlob",
      "path": "samples-output/{name}.txt",
      "connection": "AzureWebJobsStorage"
    }
  ],
  "disabled": false
}

Explanation of the Example

Common Configuration Scenarios

HTTP Trigger and Response

The fundamental binding for web APIs. The httpTrigger binding defines the URL path, HTTP methods, and authorization level. The http binding is used for the return value.

Queue Storage Binding

To process messages from a Queue Storage queue:

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

To send messages to a Queue Storage queue:

{
  "bindings": [
    {
      "name": "outputQueueItem",
      "type": "queue",
      "direction": "out",
      "queueName": "myoutputqueue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

Blob Storage Binding

To read a blob:

{
  "bindings": [
    {
      "name": "inputBlob",
      "type": "blob",
      "direction": "in",
      "path": "input-container/{blobName}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

To write a blob:

{
  "bindings": [
    {
      "name": "outputBlob",
      "type": "blob",
      "direction": "out",
      "path": "output-container/{name}.json",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

Cosmos DB Binding

To read a document from Cosmos DB:

{
  "bindings": [
    {
      "name": "inputDocument",
      "type": "cosmosDB",
      "direction": "in",
      "databaseName": "Tasks",
      "collectionName": "Items",
      "id": "{id}",
      "partitionKey": "{partitionKey}",
      "connectionStringSetting": "CosmosDBConnection"
    }
  ]
}

To write a document to Cosmos DB:

{
  "bindings": [
    {
      "name": "outputDocument",
      "type": "cosmosDB",
      "direction": "out",
      "databaseName": "Tasks",
      "collectionName": "Items",
      "createIfNotExists": false,
      "connectionStringSetting": "CosmosDBConnection"
    }
  ]
}

Connection Strings and App Settings

Connection information for services is managed through application settings. For example, the connection or connectionStringSetting properties in your function.json refer to names of settings that you configure in your Azure Function App's configuration.

Important: Never hardcode connection strings directly in your function.json. Always use application settings to securely manage your credentials.

Dynamic Paths and Parameters

Many bindings support dynamic path parameters using curly braces ({}). These parameters can be populated from:

For example, in "path": "input-container/{blobName}", {blobName} will be replaced by the actual name of the blob that triggered the function.

Advanced Configuration Options

Depending on the binding type, you can configure additional options such as:

Refer to the specific binding documentation for a full list of configurable properties.

Tip: Understanding how to leverage dynamic paths and carefully configure your bindings is key to building robust and scalable Azure Functions.

Explore the sidebar for detailed configuration examples of specific binding types.