Event-driven serverless apps with Azure Event Grid and Azure Functions

This post has been republished via RSS; it originally appeared at: Azure Global articles.

This blog post was written by AzureCAT, Paolo Salvatori.

  

Recently, a customer asked Microsoft to help them design a serverless application to receive and process events from Azure Blob Storage. They are working on a self-driving car project and have built an application that will be installed on a test car. The app allows them to capture data from a car’s GPS, gyroscope, and camera and send it to the cloud at the end of a test drive. These large files of data are processed by a Big Data solution on Azure.

EventGrid_Architecture.png

Among other things, the solution composes the individual camera images into frames that are rendered in a video. That, along with the associated GPS and gyroscope data, can be used to analyze the test car’s behavior during a drive.

Now you can see how! A sample is available on GitHub. The solution uses Azure Functions and Azure Event Grid, a fully-managed intelligent event routing service that allows you to easily build event-based solutions using a publish-subscribe model. Azure Event Grid supports a rich set of Event Sources and Event Handlers that can be used to build an event-driven serverless or microservice-based solution.

The GitHub sample demonstrates how to create a serverless application to receive and process events any time a blob is created, updated, or deleted in a given container inside an Azure storage account. We showed the customer how to adopt this approach using Azure Functions to process events with a serverless application. Azure Functions allow you to easily run small pieces of code, known as functions, in the cloud in a fully managed environment without the need to provision or maintain a whole hosting infrastructure. You can use the programming language of choice, such as C#, F#, Node.js, Java, or PHP, to build Azure Functions. (Our sample uses C#.) You pay only for the time your code runs, and you can trust Azure to scale your functions as needed.

The solution triggers the execution of a blob processing solution as soon as new files are written to a given storage account. In the sample, Azure Function sends a message containing the data of the new blob to a Service Bus queue to trigger the execution of a hypothetical Big Data solution.

The GitHub sample includes all the bash scripts required to provision the Azure Event Grid Subscriptions using the Azure CLI commands for Azure Event Grids topics and subscriptions. The sample GitHub scripts show how to:

  • Use bash scripts to create Event Grid Subscriptions for the Azure Function, Event Grid Viewer Web App and Function App running on the dev machine using Ngrok. For more information, see Azure Function Event Grid Trigger Local Debugging.
  • Instrument the Azure Function to generate custom metrics.
  • Use Application Insights to analyze Azure Function logs, metrics and custom metrics.

Together, the Event Grid trigger and Azure Functions give you a lot of power, and this solution has many applications. You can generalize this approach to create an Azure Function to handle any event generated by an Event Grid event producer, including Azure Subscriptions, Resource Groups, and Azure Event Hubs. For more information, see other code samples for Azure Event Grid.

The GitHub solution also demonstrates how to do local testing and debug an Azure Function that uses the Event Grid trigger on your local machine before publishing the application to Azure.

Check out the GitHub sample!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.