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:
The following example shows the function definition after adding a Queue Storage output binding to an HTTP triggered function:
[FunctionName("HttpExample")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[Queue("outqueue"),StorageAccount("AzureWebJobsStorage")] ICollector<string> msg,
ILogger log)
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.
Service | Examples | Samples |
---|---|---|
Blob storage | Trigger Input Output |
Link |
Azure Cosmos DB | Trigger Input Output |
Link |
Azure SQL | Trigger (preview) 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 |
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: