Bindings for Azure Functions

Bindings are a declarative way to connect to data sources and services. Bindings reduce the amount of boilerplate code you need to write in your function. They let you declare how functions are connected to external data and events, and how functions execute, without needing to write code to interact with those other services.

Key Concept: Bindings provide a declarative approach to input and output, abstracting the complexities of data source interactions.

Types of Bindings

Bindings can be categorized as either triggers or other bindings:

Common Bindings

Azure Functions supports a wide variety of bindings for popular Azure services and external systems:

Binding Type Description Example Use Cases
HTTP Trigger Executes a function in response to an HTTP request. Web APIs, webhook handlers.
Timer Trigger Executes a function on a schedule defined by a cron expression. Scheduled tasks, background jobs.
Blob Storage Input/Output Reads from or writes to Azure Blob Storage. Processing uploaded files, saving function output.
Queue Storage Input/Output Reads from or writes to Azure Queue Storage. Decoupling services, message processing.
Cosmos DB Input/Output Reads from or writes to Azure Cosmos DB. Data persistence, document retrieval.
Service Bus Input/Output Reads from or writes to Azure Service Bus queues or topics. Enterprise messaging patterns.
Event Hubs Input/Output Reads from or writes to Azure Event Hubs. Real-time data streaming, IoT data processing.
Table Storage Input/Output Reads from or writes to Azure Table Storage. Storing simple structured data.

Binding Configuration

Bindings are typically configured in a function.json file (for Node.js, Python, Java, etc.) or through attributes in code (for .NET).

Example: function.json for an HTTP Trigger with a Blob Output

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

In this example:

Note: The name property in a binding definition corresponds to the parameter name in your function code.

Custom Bindings

For scenarios not covered by built-in bindings, you can create custom bindings to integrate with your own services or specific protocols.

Next Steps