Azure function App
2 TopicsPush Blob Storage events to Azure Storage Table using Azure Function App
Scenario: In this blog, we will cover the steps to trigger an Azure Function App based on any of the Azure Blob Storage events and log the events to the Azure table storage. Below is the step by step approach to accomplish this requirement: Pre-Requisites: Azure Storage GPV2 account Function App Event Grid Step 1: Create an Azure Function APP To create function app we will leverage this article. Once the function app is created, you should see all its resource dependencies like below: Click on the Azure Function app which you just created and then you will be able to see the blade as shown below. Click on Plus (+) Sign to add Function, select Event Grid trigger and function name: On your local computer, create a file named “function.proj” and paste the below content in it: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" /> </ItemGroup> </Project> Click on the +Add file and Upload the “function.proj” to the Function app. Make sure you update the correct package version from Nuget https://www.nuget.org/packages/WindowsAzure.Storage/ Double click on “csx” file to edit the content and paste the below code snippet to push the event to Azure Table Storage. #r "Microsoft.Azure.EventGrid" using Microsoft.Azure.EventGrid.Models; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Table; using System.Threading.Tasks; public static void Run(EventGridEvent eventGridEvent, ILogger log) { CloudStorageAccount storageAccount = new CloudStorageAccount( new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("MyStorage", "yvQCeS8/ok************************** "), true); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable test = tableClient.GetTableReference("EventsData"); TableData data = new TableData(eventGridEvent.Data.ToString()); data.data = eventGridEvent.Data.ToString(); // Create the TableOperation that inserts the customer entity. TableOperation insertOperation = TableOperation.Insert(data); // Execute the insert operation. test.ExecuteAsync(insertOperation); log.LogInformation(eventGridEvent.Data.ToString()); } public class TableData : TableEntity { public TableData(string data) { this.PartitionKey = Guid.NewGuid().ToString(); this.RowKey = Guid.NewGuid().ToString(); } public TableData() { } public string data { get; set; } } You can test if the newly created Function app is running without any issues, as per the below screenshot: Once the function app is created and tested successfully. You need to click on the Integrate setting in the function app blade to integrate with the Event Grid. You need to copy the Event Grid subscription URL as this will be used as a webhook subscriber endpoint in Azure Event Grid. Enable Blob events The steps to create storage account and configure event grid is discusssed here. Follow the below steps to configure the event grid to react to the storage events: Once you have created a GPv2 storage account, go to your storage account and click the Events settings in the middle blade and click on the Event Subscription button: Here you need to add the webhook endpoint which you had copied in Step 8 mentioned above. You can test the functionality using storage explorer by uploading a blob to your storage account. You should be able to see the blob events in the Azure Table storage. Attached: proj csx4.4KViews2likes1CommentAzure Database for MySQL bindings for Azure Functions (General Availability)
We’re thrilled to announce the general availability (GA) of Azure Database for MySQL Input and Output bindings for Azure Functions—a powerful way to build event-driven, serverless applications that seamlessly integrate with your MySQL databases. Key Capabilities With this GA release, your applications can use: Input bindings that allow your function to retrieve data from a MySQL database without writing any connection or query logic. Output bindings that allow your function to insert or update data in a MySQL table without writing explicit SQL commands. In addition you can use both the input and output bindings in the same function to read-modify-write data patterns. For example, retrieve a record, update a field, and write it back—all without managing connections or writing SQL. These bindings are fully supported for both in-process and isolated worker models, giving you flexibility in how you build and deploy your Azure Functions. How It Works Azure Functions bindings abstract away the boilerplate code required to connect to external services. With the MySQL Input and Output bindings, you can now declaratively connect your serverless functions to your Azure Database for MySQL database with minimal configuration. You can configure these bindings using attributes in C#, decorators in Python, or annotations in JavaScript/Java. The bindings use the MySql.Data.MySqlClient library under the hood and support Azure Database for MySQL Flexible Server. Getting Started To use the bindings, install the appropriate NuGet or npm package: # For isolated worker model (C#) dotnet add package Microsoft.Azure.Functions.Worker.Extensions.MySql # For in-process model (C#) dotnet add package Microsoft.Azure.WebJobs.Extensions.MySql Then, configure your function with a connection string and binding metadata. Full samples for all the supported programming frameworks are available in our github repository. Here is a sample C# in-process function example where you want to retrieve a user by ID, increment their login count, and save the updated record back to the MySQL database for lightweight data transformations, modifying status fields or updating counters and timestamps. public class User { public int Id { get; set; } public string Name { get; set; } public int LoginCount { get; set; } } public static class UpdateLoginCountFunction { [FunctionName("UpdateLoginCount")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "user/{id}/login")] HttpRequest req, [MySql("SELECT * FROM users WHERE id = @id", CommandType = System.Data.CommandType.Text, Parameters = "@id={id}", ConnectionStringSetting = "MySqlConnectionString")] User user, [MySql("users", ConnectionStringSetting = "MySqlConnectionString")] IAsyncCollector<User> userCollector, ILogger log) { if (user == null) { return new NotFoundObjectResult("User not found."); } // Modify the user object user.LoginCount += 1; // Write the updated user back to the database await userCollector.AddAsync(user); return new OkObjectResult($"Login count updated to {user.LoginCount} for user {user. Name}."); } } Learn More Azure Functions MySQL Bindings Azure Functions Conclusion With input and output bindings for Azure Database for MySQL now generally available, building serverless apps on Azure with MySQL has never been simpler or more efficient. By eliminating the need for manual connection management and boilerplate code, these bindings empower you to focus on what matters most: building scalable, event-driven applications with clean, maintainable code. Whether you're building real-time dashboards, automating workflows, or syncing data across systems, these bindings unlock new levels of productivity and performance. We can’t wait to see what you’ll build with them. If you have any feedback or questions about the information provided above, please leave a comment below or email us at AskAzureDBforMySQL@service.microsoft.com. Thank you!