Azure Functions Storage Bindings

Storage bindings in Azure Functions enable your functions to interact with various Azure storage services like Blob Storage, Table Storage, Queue Storage, and Cosmos DB in a declarative way. This simplifies data access by abstracting away the complexities of the storage SDKs.

Supported Storage Services

Azure Functions provide built-in support for the following storage services:

Types of Bindings

Storage bindings can be used in two primary ways:

Input Bindings

Input bindings allow you to read data from a storage service and pass it as an argument to your function. The runtime handles fetching the data before your function code is executed.

Example: Reading a blob file

In your function.json:


{
  "bindings": [
    {
      "name": "myBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "samples-workitems/{name}.txt",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "fileContent",
      "type": "blob",
      "direction": "in",
      "path": "samples-workitems/{name}.txt",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
            

In your C# function:


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

public static class BlobInputExample
{
    public static void Run(
        [BlobTrigger("samples-workitems/{name}.txt", Connection = "AzureWebJobsStorage")] Stream myBlob,
        string name,
        [Blob("samples-workitems/{name}.txt", Connection = "AzureWebJobsStorage")] string fileContent,
        ILogger log)
    {
        log.LogInformation($"C# Blob trigger function processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        log.LogInformation($"File content: {fileContent}");
    }
}
            

Output Bindings

Output bindings allow your function to write data to a storage service. The runtime handles sending the data after your function has successfully executed.

Example: Writing to a blob

In your function.json:


{
  "bindings": [
    {
      "name": "inputQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputBlob",
      "type": "blob",
      "direction": "out",
      "path": "output-blobs/{rand-guid}.txt",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
            

In your C# function:


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

public static class BlobOutputExample
{
    public static void Run(
        string inputQueueItem,
        [Blob("output-blobs/{rand-guid}.txt", Connection = "AzureWebJobsStorage")] out string outputBlob,
        ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed: {inputQueueItem}");
        outputBlob = $"Processed: {inputQueueItem}";
    }
}
            

Configuration

Storage bindings are configured in the function.json file (or via attributes in compiled languages). Key properties include:

Connection Strings

Connection strings for Azure Storage services are typically stored in your function app's application settings. The default connection name is AzureWebJobsStorage, which often points to your primary Azure Storage account.

Common Connection Settings:

Advanced Scenarios

Storage bindings offer flexibility for various use cases, including:

For detailed examples and specific configurations for each storage service, please refer to the official Azure Functions documentation for Blob Storage Bindings, Queue Storage Bindings, and Cosmos DB Bindings.