Connect functions to Azure services using bindings

When you create a function, language-specific trigger code is added in your project from a set of trigger templates. If you want to connect your function to other services by using input or output bindings, you have to add specific binding definitions in your function. To learn more about bindings, see Azure Functions triggers and bindings concepts.

Local development

When you develop functions locally, you need to update the function code to add bindings. For languages that use function.json, Visual Studio Code provides tooling to add bindings to a function.

Manually add bindings based on examples

When adding a binding to an existing function, you need to add binding-specific attributes to the function definition in code.

When adding a binding to an existing function, you need to add binding-specific annotations to the function definition in code.

When adding a binding to an existing function, you need to update the function code and add a definition to the function.json configuration file.

When adding a binding to an existing function, you need update the function definition, depending on your model:

You need to add binding-specific annotations to the function definition in code.

The following example shows the function definition after adding a Queue Storage output binding to an HTTP triggered function:

Because an HTTP triggered function also returns an HTTP response, the function returns a MultiResponse object, which represents both the HTTP and queue output.

[Function("HttpExample")]
public static MultiResponse Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
    FunctionContext executionContext)
{

This example is the definition of the MultiResponse object that includes the output binding:

public class MultiResponse
{
    [QueueOutput("outqueue",Connection = "AzureWebJobsStorage")]
    public string[] Messages { get; set; }
    public IActionResult HttpResponse { get; set; }
}

When applying that example to your own project, you might need to change HttpRequest to HttpRequestData and IActionResult to HttpResponseData, depending on if you are using ASP.NET Core integration or not.

Messages are sent to the queue when the function completes. The way you define the output binding depends on your process model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.

@FunctionName("HttpExample")
public HttpResponseMessage run(
        @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) 
        HttpRequestMessage<Optional<String>> request, 
        @QueueOutput(name = "msg", queueName = "outqueue", 
        connection = "AzureWebJobsStorage") OutputBinding<String> msg, 
        final ExecutionContext context) {

For more information, including links to example binding code that you can refer to, see Add bindings to a function.

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "queue",
      "direction": "out",
      "name": "msg",
      "queueName": "outqueue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

The way you define the output binding depends on the version of your Node.js model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.

$outputMsg = $name
Push-OutputBinding -name msg -Value $outputMsg

For more information, including links to example binding code that you can refer to, see Add bindings to a function.

@app.route(route="HttpExample")
@app.queue_output(arg_name="msg", queue_name="outqueue", connection="AzureWebJobsStorage")
def HttpExample(req: func.HttpRequest, msg: func.Out [func.QueueMessage]) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

The way you define the output binding depends on the version of your Python model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "queue",
      "direction": "out",
      "name": "msg",
      "queueName": "outqueue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

The way you define the output binding depends on the version of your Node.js model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.

Use the following table to find examples of specific binding types that you can use to guide you in updating an existing function. First, choose the language tab that corresponds to your project.

Binding code for C# depends on the specific process model.

Service Examples Samples
Blob storage Trigger
Input
Output
Link
Azure Cosmos DB Trigger
Input
Output
Link
Azure Data Explorer Input
Output
Link
Azure SQL Trigger
Input
Output
Link
Event Grid Trigger
Output
Link
Event Hubs Trigger
Output
IoT Hub Trigger
Output
HTTP Trigger Link
Queue storage Trigger
Output
Link
RabbitMQ Trigger
Output
SendGrid Output
Service Bus Trigger
Output
Link
SignalR Trigger
Input
Output
Table storage Input
Output
Timer Trigger Link
Twilio Output Link
Service Examples Samples
Blob storage Trigger
Input
Output
Link
Azure Cosmos DB Trigger
Input
Output
Link
Azure Data Explorer Input
Output
Link
Azure SQL Trigger
Input
Output
Event Grid Trigger
Output
Link
Event Hubs Trigger
Output
IoT Hub Trigger
Output
HTTP Trigger Link
Queue storage Trigger
Output
Link
RabbitMQ Trigger
Output
SendGrid Output
Service Bus Trigger
Output
Link
SignalR Trigger
Input
Output
Table storage Input
Output
Timer Trigger Link
Twilio Output Link
Service Examples Samples
Blob storage Trigger
Input
Output
Link
Azure Cosmos DB Trigger
Input
Output
Link
Azure Data Explorer Input
Output
Azure SQL Trigger
Input
Output
Link
Event Grid Trigger
Output
Link
Event Hubs Trigger
Output
IoT Hub Trigger
Output
HTTP Trigger Link
Queue storage Trigger
Output
Link
RabbitMQ Trigger
Output
SendGrid Output
Service Bus Trigger
Output
Link
SignalR Trigger
Input
Output
Table storage Input
Output
Timer Trigger Link
Twilio Output Link
Service Examples Samples
Blob storage Trigger
Input
Output
Link
Azure Cosmos DB Trigger
Input
Output
Link
Azure SQL Trigger
Input
Output
Event Grid Trigger
Output
Link
Event Hubs Trigger
Output
IoT Hub Trigger
Output
HTTP Trigger Link
Queue storage Trigger
Output
Link
RabbitMQ Trigger
Output
SendGrid Output
Service Bus Trigger
Output
Link
SignalR Trigger
Input
Output
Table storage Input
Output
Timer Trigger Link
Twilio Output Link

Binding code for Python depends on the Python model version.

Service Examples Samples
Blob storage Trigger
Input
Output
Link
Azure Cosmos DB Trigger
Input
Output
Link
Azure Data Explorer Input
Output
Azure SQL Trigger
Input
Output
Link
Event Grid Trigger
Output
Link
Event Hubs Trigger
Output
IoT Hub Trigger
Output
HTTP Trigger Link
Queue storage Trigger
Output
Link
RabbitMQ Trigger
Output
SendGrid Output
Service Bus Trigger
Output
Link
SignalR Trigger
Input
Output
Table storage Input
Output
Timer Trigger Link
Twilio Output Link

Visual Studio Code

When you use Visual Studio Code to develop your function and your function uses a function.json file, the Azure Functions extension can automatically add a binding to an existing function.json file. To learn more, see Add input and output bindings.

Azure portal

When you develop your functions in the Azure portal, you add input and output bindings in the Integrate tab for a given function. The new bindings are added to either the function.json file or to the method attributes, depending on your language. The following articles show examples of how to add bindings to an existing function in the portal:

Next steps