Integrate Azure Functions and Azure SQL easily with the Azure SQL bindings for Azure Functions, now generally available. Input and output bindings speed up development time by reducing boilerplate code required to read and write from the database in .NET, Python, Node.js, Java, and PowerShell Azure Functions. Azure SQL bindings for Azure Functions are compatible with Azure SQL Database, Azure SQL Managed Instance, and SQL Server 2016-2022.
With Azure SQL bindings, data can be input from a database to the function with an input binding and data can be output from the function to the database. Configuring these bindings is accomplished with a small number of parameters, including specification of the database query or table and the connection string.
An input binding can execute a query or a stored procedure, and the results are passed to the function as an object. The following example .NET Azure Function executes the query “SELECT TOP 10 ProductId, ProductName FROM Sales.Products ORDER BY CreatedDate DESC” when an HTTP GET request is made to the /newproducts endpoint. Data is read from SQL into the newProducts object at the beginning of the function before being returned as the HTTP response content.
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "newproducts")]
[Sql(commandText: "SELECT TOP 10 ProductId, ProductName FROM Sales.Products ORDER BY CreatedDate DESC",
return new OkObjectResult(newProducts);
The use of Azure Active Directory Managed Identity authentication with Azure SQL bindings enables passwordless authentication to Azure SQL. The setup requires enabling system-assigned or user-assigned managed identity on an Azure Functions instance and using a connection string setting with Authentication=”Active Directory Managed Identity”. Managed identities make your app more secure by eliminating secrets from your app and are ready for use with Azure SQL bindings for Azure Functions. Learn how you can enable passwordless authentication on your Azure Functions in minutes in this tutorial: https://learn.microsoft.com/azure/azure-functions/functions-identity-access-azure-sql-with-managed-i...
SQL trigger (preview)
In addition to input and output bindings, an Azure Function can be triggered by data changes in Azure SQL. With the Azure SQL trigger you can invoke Azure Functions from data changes to develop event-driven applications on your Azure SQL databases.
Several code samples are available that highlight the use of SQL bindings with an HTTP trigger to create APIs:
Azure SQL bindings are applicable to functions that are triggered by any event, including timers, Azure Service Bus, and Azure Blob Storage. This Python Functions sample with SQL input bindings shows how to accomplish a common scenario of sending data on a schedule from SQL to an FTP server or other integration service: https://github.com/Azure-Samples/sqlbindings-python-datatransfer