What are Azure Functions Bindings?
Bindings in Azure Functions provide a declarative way to connect your function code to other Azure services and external data sources. They abstract away the complexities of service integration, allowing you to focus on your function's business logic. Bindings can be used to trigger a function (trigger bindings) or to read and write data to other services (input and output bindings).
Key Concepts
Trigger Bindings
A trigger binding defines what causes your function to execute. It specifies the event that starts your function.
- Each function must have exactly one trigger.
- Examples: HTTP Trigger, Timer Trigger, Blob Trigger, Queue Trigger, Cosmos DB Trigger.
Input Bindings
Input bindings allow you to read data from other services or data sources into your function.
- You can define multiple input bindings.
- Data is made available as parameters to your function.
- Examples: Blob Input, Table Input, Cosmos DB Input, Service Bus Input.
Output Bindings
Output bindings enable you to write data to other services or data sinks from your function.
- You can define multiple output bindings.
- The return value of your function or specific output parameters are used to write data.
- Examples: Blob Output, Table Output, Cosmos DB Output, Service Bus Output.
Common Binding Types
Triggers
HTTP Trigger
Executes your function in response to an HTTP request.
Timer Trigger
Executes your function on a schedule defined by a cron expression.
Blob Trigger
Executes your function when a new or updated blob is detected in Azure Blob Storage.
Inputs & Outputs
Blob Storage
Read/write blobs to Azure Blob Storage.
Azure Cosmos DB
Read/write documents from/to Azure Cosmos DB.
Azure Service Bus
Send/receive messages from Azure Service Bus queues and topics.
Azure Table Storage
Read/write entities to Azure Table Storage.
Configuration
Bindings are configured using a `function.json` file (for JavaScript, Python, and PowerShell) or through attributes/decorators (for C# and Java) in your project.
{
"scriptFile": "../run.js",
"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": "input-container/{name}.txt",
"connection": "AzureWebJobsStorage"
},
{
"type": "blob",
"direction": "out",
"name": "outputBlob",
"path": "output-container/{name}.txt",
"connection": "AzureWebJobsStorage"
}
]
}
The `direction` property specifies whether a binding is `in` (trigger or input binding) or `out` (output binding). The `name` property is how the binding is referenced within your function code.