In this article, you learn the high-level concepts surrounding functions triggers and bindings.
Triggers cause a function to run. A trigger defines how a function is invoked and a function must have exactly one trigger. Triggers can also pass data into your function, as you would with method calls.
Binding to a function is a way of declaratively connecting your functions to other resources; bindings either pass data into your function (an input binding) or enable you to write data out from your function (an output binding) using binding parameters. Your function trigger is essentially a special type of input binding.
You can mix and match different bindings to suit your function's specific scenario. Bindings are optional and a function might have one or multiple input and/or output bindings.
Triggers and bindings let you avoid hardcoding access to other services. Your function receives data (for example, the content of a queue message) in function parameters. You send data (for example, to create a queue message) by using the return value of the function.
Consider the following examples of how you could implement different functions.
Example scenario
Trigger
Input binding
Output binding
A new queue message arrives which runs a function to write to another queue.
Queue*
None
Queue*
A scheduled job reads Blob Storage contents and creates a new Azure Cosmos DB document.
Timer
Blob Storage
Azure Cosmos DB
The Event Grid is used to read an image from Blob Storage and a document from Azure Cosmos DB to send an email.
Event Grid
Blob Storage and Azure Cosmos DB
SendGrid
* Represents different queues
These examples aren't meant to be exhaustive, but are provided to illustrate how you can use triggers and bindings together. For a more comprehensive set of scenarios, see Azure Functions scenarios.
Tip
Functions doesn't require you to use input and output bindings to connect to Azure services. You can always create an Azure SDK client in your code and use it instead for your data transfers. For more information, see Connect to services.
Trigger and binding definitions
A function has a single trigger and one or more bindings. The type of binding is either input or output. Not all services support both input and output bindings. See your specific binding extension for specific bindings code examples.
Triggers and bindings are defined differently depending on the development language. Make sure to select your language at the top of the article.
This example shows an HTTP triggered function with an output binding that writes a message to an Azure Storage queue.
For C# class library functions, triggers and bindings are configured by decorating methods and parameters with C# attributes, where the specific attribute applied might depend on the C# runtime model:
This example shows the MultiResponse object definition which both returns an HttpResponse to the HTTP request and also writes a message to a storage queue using a QueueOutput binding:
public class MultiResponse
{
[QueueOutput("outqueue",Connection = "AzureWebJobsStorage")]
public string[] Messages { get; set; }
public HttpResponseData HttpResponse { get; set; }
}
The HTTP trigger (HttpTrigger) is defined on the Run method for a function named HttpExample that writes to a storage queue defined by the Queue and StorageAccount attributes on the msg parameter:
For Java functions, triggers and bindings are configured by annotating specific methods and parameters. This HTTP trigger (@HttpTrigger) is defined on the run method for a function named HttpTriggerQueueOutput, which writes to a storage queue defined by the @QueueOutput annotation on the message parameter:
In Node.js for Functions version 4, you configure triggers and bindings using objects exported from the @azure/functions module. For more information, see the Node.js developer guide.
In Node.js for Functions version 3, you configure triggers and bindings in a function-specific function.json file in the same folder as your code. For more information, see the Node.js developer guide.
This example is an HTTP triggered function that creates a queue item for each HTTP request received.
In Python for Functions version 1, this example function.json file defines an HTTP trigger function that returns an HTTP response and writes to a storage queue.
You can connect your function to other services by using input or output bindings. Add a binding by adding its specific definitions to your function. To learn how, see Add bindings to an existing function in Azure Functions.
Azure Functions supports multiple bindings, which must be configured correctly. For example, a function can read data from a queue (input binding) and write data to a database (output binding) simultaneously.
Supported bindings
This table shows the bindings that are supported in the major versions of the Azure Functions runtime:
Supported in Kubernetes, IoT Edge, and other self-hosted modes only.
For information about which bindings are in preview or are approved for production use, see Supported languages.
Specific binding extension versions are only supported while the underlying service SDK is supported. Changes to support in the underlying service SDK version affect the support for the consuming extension.
Bindings code examples
Use the following table to find more examples of specific binding types that show you how to work with bindings in your functions. First, choose the language tab that corresponds to your project.
You can create custom input and output bindings. Bindings must be authored in .NET, but can be consumed from any supported language. For more information about creating custom bindings, see Creating custom input and output bindings.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.