Azure Functions Bindings Configuration

This document details how to configure bindings for Azure Functions. Bindings provide a declarative way to connect to other Azure services and various external resources. They simplify your function code by abstracting away the details of connecting to and interacting with these services.

Understanding Binding Configuration

Bindings are defined in the function.json file for each function or within the host.json file for globally applied configurations. The structure of the function.json file typically includes an array of binding objects, each specifying:

  • type: The type of the binding (e.g., httpTrigger, blob, queue).
  • direction: Whether the binding is an in (input), out (output), or inout binding.
  • name: The name of the parameter in your function code that the binding maps to.
  • ...other properties: Service-specific properties like connection strings, container names, queue names, etc.

Example: function.json for an HTTP Trigger and Blob Output

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "blob",
      "direction": "out",
      "name": "outputBlob",
      "path": "output-container/{rand-guid}.txt",
      "connection": "AzureWebJobsStorage"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

Common Binding Properties

While specific properties vary by binding type, some are common across many bindings:

  • type: Specifies the service to integrate with (e.g., httpTrigger, blob, queueTrigger, cosmosDB, eventHubTrigger).
  • direction: in for input, out for output.
  • name: The name of the variable in your function's code that represents the data for this binding.
  • connection: The name of an app setting that contains the connection string for the service. If omitted, the default AzureWebJobsStorage is used.

httpTrigger Binding Properties

  • authLevel: (anonymous, function, admin) Defines access restrictions.
  • methods: An array of HTTP methods the trigger will respond to (e.g., GET, POST).
  • route: Custom route for the HTTP endpoint.

blob Binding Properties

  • path: The path to the blob, supporting wildcard matching and tokens like {name}, {rand-guid}.
  • connection: App setting name for the storage account connection string.

queueTrigger Binding Properties

  • queueName: The name of the queue to monitor.
  • connection: App setting name for the storage account connection string.

Connection Strings and App Settings

Connection strings for external services are typically stored in your Azure Function App's application settings. Bindings reference these settings using the connection property. This is a crucial security practice to avoid hardcoding sensitive credentials directly in your function code or configuration files.

Tip: Always use app settings for connection strings. For local development, these are managed in your local.settings.json file.

Global Configuration with host.json

The host.json file allows you to configure settings that apply to all functions within a function app. This includes settings for:

  • version: The schema version of the host.json file.
  • extensionBundle: Configures the version of the extension bundles used by your function app.
  • logging: Settings for how logs are handled.
  • singleton: Settings for singleton execution.
  • concurrency: Settings for concurrency control.

Example: host.json with Extension Bundle and Logging Configuration

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

Understanding and correctly configuring bindings is key to building robust and scalable serverless applications with Azure Functions. Refer to the specific binding documentation for detailed property explanations and advanced configurations.