Home
%3CLINGO-SUB%20id%3D%22lingo-sub-355634%22%20slang%3D%22en-US%22%3EEvent-driven%20serverless%20apps%20with%20Azure%20Event%20Grid%20and%20Azure%20Functions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-355634%22%20slang%3D%22en-US%22%3E%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3EThis%20blog%20post%20was%20written%20by%20AzureCAT%2C%20%3CEM%3E%3CSTRONG%3EPaolo%20Salvatori%3C%2FSTRONG%3E%3C%2FEM%3E.%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3E%26nbsp%3B%26nbsp%3B%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3ERecently%2C%20a%20customer%20asked%20Microsoft%20to%20help%20them%20design%20a%20serverless%20application%20to%20receive%20and%20process%20events%20from%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fblobs%2Fstorage-blobs-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Blob%20Storage%3C%2FA%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E.%20They%20are%20working%20on%20a%20self-driving%20car%20project%20and%20have%20built%20an%20application%20that%20will%20be%20installed%20on%20a%20test%20car.%20The%20app%20allows%20them%20to%20capture%20data%20from%20a%20car%E2%80%99s%20GPS%2C%20gyroscope%2C%20and%20camera%20and%20send%20it%20to%20the%20cloud%20at%20the%20end%20of%20a%20test%20drive.%20These%20large%20files%20of%20data%20are%20processed%20by%20a%20Big%20Data%20solution%20on%20Azure.%20%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F84147i2D8B4B52220F4961%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22EventGrid_Architecture.png%22%20title%3D%22EventGrid_Architecture.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3EAmong%20other%20things%2C%20the%20solution%20composes%20the%20individual%20camera%20images%20into%20frames%20that%20are%20rendered%20in%20a%20video.%20That%2C%20along%20with%20the%20associated%20GPS%20and%20gyroscope%20data%2C%20can%20be%20used%20to%20analyze%20the%20test%20car%E2%80%99s%20behavior%20during%20a%20drive.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3ENow%20you%20can%20see%20how!%20A%20sample%20is%20available%20on%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpaolosalvatori%2Fblob-event-grid-function-app%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%3C%2FA%3E%3C%2FSPAN%3E%3CFONT%20color%3D%22%23000000%22%3E.%20The%20solution%20uses%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Functions%3C%2FA%3E%3C%2FSPAN%3E%3CFONT%20color%3D%22%23000000%22%3E%20and%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fevent-grid%2Foverview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Event%20Grid%3C%2FA%3E%3C%2FSPAN%3E%3CFONT%20color%3D%22%23000000%22%3E%2C%20a%20fully-managed%20intelligent%20event%20routing%20service%20that%20allows%20you%20to%20easily%20build%20event-based%20solutions%20using%20a%20publish-subscribe%20model.%20Azure%20Event%20Grid%20supports%20a%20rich%20set%20of%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fevent-grid%2Fevent-sources%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EEvent%20Sources%3C%2FA%3E%3C%2FSPAN%3E%3CFONT%20color%3D%22%23000000%22%3E%20and%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fevent-grid%2Fevent-handlers%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EEvent%20Handlers%3C%2FA%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E%20that%20can%20be%20used%20to%20build%20an%20event-driven%20serverless%20or%20microservice-based%20solution.%20%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3EThe%20GitHub%20sample%20demonstrates%20how%20to%20create%20a%20serverless%20application%20to%20receive%20and%20process%20events%20any%20time%20a%20blob%20is%20created%2C%20updated%2C%20or%20deleted%20in%20a%20given%20container%20inside%20an%20Azure%20storage%20account.%20We%20showed%20the%20customer%20how%20to%20adopt%20this%20approach%20using%20Azure%20Functions%20to%20process%20events%20with%20a%20serverless%20application.%20Azure%20Functions%20allow%20you%20to%20easily%20run%20small%20pieces%20of%20code%2C%20known%20as%20functions%2C%20in%20the%20cloud%20in%20a%20fully%20managed%20environment%20without%20the%20need%20to%20provision%20or%20maintain%20a%20whole%20hosting%20infrastructure.%20You%20can%20use%20the%20programming%20language%20of%20choice%2C%20such%20as%20C%23%2C%20F%23%2C%20Node.js%2C%20Java%2C%20or%20PHP%2C%20to%20build%20Azure%20Functions.%20(Our%20sample%20uses%20C%23.)%20You%20pay%20only%20for%20the%20time%20your%20code%20runs%2C%20and%20you%20can%20trust%20Azure%20to%20scale%20your%20functions%20as%20needed.%20%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3EThe%20solution%20triggers%20the%20execution%20of%20a%20blob%20processing%20solution%20as%20soon%20as%20new%20files%20are%20written%20to%20a%20given%20storage%20account.%20In%20the%20sample%2C%20Azure%20Function%20sends%20a%20message%20containing%20the%20data%20of%20the%20new%20blob%20to%20a%20Service%20Bus%20queue%20to%20trigger%20the%20execution%20of%20a%20hypothetical%20Big%20Data%20solution.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3EThe%20GitHub%20sample%20includes%20all%20the%20bash%20scripts%20required%20to%20provision%20the%20Azure%20Event%20Grid%20Subscriptions%20using%20the%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Feventgrid%3Fview%3Dazure-cli-latest%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20CLI%3C%2FA%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E%20commands%20for%20Azure%20Event%20Grids%20topics%20and%20subscriptions.%20The%20sample%20GitHub%20scripts%20show%20how%20to%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CUL%20type%3D%22disc%22%20style%3D%22margin-top%3A%200in%3B%22%3E%0A%3CLI%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%20color%3A%20%23000000%3B%20font-family%3A%20'Segoe%20UI'%2Csans-serif%3B%20font-size%3A%2011pt%3B%20font-style%3A%20normal%3B%20font-weight%3A%20400%3B%22%3EUse%20bash%20scripts%20to%20create%20Event%20Grid%20Subscriptions%20for%20the%20Azure%20Function%2C%20Event%20Grid%20Viewer%20Web%20App%20and%20Function%20App%20running%20on%20the%20dev%20machine%20using%20%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fngrok.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ENgrok%3C%2FA%3E%3C%2FSPAN%3E.%20For%20more%20information%2C%20see%20%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-debug-event-grid-trigger-local%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Function%20Event%20Grid%20Trigger%20Local%20Debugging%3C%2FA%3E%3C%2FSPAN%3E.%3C%2FLI%3E%0A%3CLI%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%20color%3A%20%23000000%3B%20font-family%3A%20'Segoe%20UI'%2Csans-serif%3B%20font-size%3A%2011pt%3B%20font-style%3A%20normal%3B%20font-weight%3A%20400%3B%22%3EInstrument%20the%20Azure%20Function%20to%20generate%20custom%20metrics.%3C%2FLI%3E%0A%3CLI%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%20color%3A%20%23000000%3B%20font-family%3A%20'Segoe%20UI'%2Csans-serif%3B%20font-size%3A%2011pt%3B%20font-style%3A%20normal%3B%20font-weight%3A%20400%3B%22%3EUse%20Application%20Insights%20to%20analyze%20Azure%20Function%20logs%2C%20metrics%20and%20custom%20metrics.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3ETogether%2C%20the%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-event-grid%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EEvent%20Grid%20trigger%3C%2FA%3E%3C%2FSPAN%3E%3CFONT%20color%3D%22%23000000%22%3E%20and%20Azure%20Functions%20give%20you%20a%20lot%20of%20power%2C%20and%20this%20solution%20has%20many%20applications.%20You%20can%20generalize%20this%20approach%20to%20create%20an%20Azure%20Function%20to%20handle%20any%20event%20generated%20by%20an%20Event%20Grid%20event%20producer%2C%20including%20Azure%20Subscriptions%2C%20Resource%20Groups%2C%20and%20Azure%20Event%20Hubs.%20For%20more%20information%2C%20see%20other%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fit-it%2Fresources%2Fsamples%2F%3Fsort%3D0%26amp%3Bservice%3Devent-grid%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecode%20samples%3C%2FA%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E%20for%20Azure%20Event%20Grid.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3EThe%20GitHub%20solution%20also%20demonstrates%20how%20to%20do%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-event-grid%23local-testing-with-viewer-web-app%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elocal%20testing%3C%2FA%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E%20and%20debug%20an%20Azure%20Function%20that%20uses%20the%20Event%20Grid%20trigger%20on%20your%20local%20machine%20before%20publishing%20the%20application%20to%20Azure.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200px%200px%2013.33px%3B%20text-align%3A%20justify%3B%22%3E%3CFONT%20face%3D%22Segoe%20UI%22%3E%3CFONT%20color%3D%22%23000000%22%3ECheck%20out%20the%20%3C%2FFONT%3E%3CSPAN%20style%3D%22margin%3A%200px%3B%22%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpaolosalvatori%2Fblob-event-grid-function-app%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%20sample%3C%2FA%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%20face%3D%22Segoe%20UI%22%3E!%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-355634%22%20slang%3D%22en-US%22%3E%3CP%20style%3D%22background-color%3A%20transparent%3B%20color%3A%20%23000000%3B%20font-family%3A%20Times%20New%20Roman%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20400%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3ERecently%2C%20a%20customer%20asked%20Microsoft%20to%20help%20them%20design%20a%20serverless%20application%20to%20receive%20and%20process%20events%20from%20Azure%20Blob%20Storage.%20They%20are%20working%20on%20a%20self-driving%20car%20project%20and%20have%20built%20an%20application%20that%20will%20be%20installed%20on%20a%20test%20car.%20The%20app%20allows%20them%20to%20capture%20data%20from%20a%20car%E2%80%99s%20GPS%2C%20gyroscope%2C%20and%20camera%20and%20send%20it%20to%20the%20cloud%20at%20the%20end%20of%20a%20test%20drive.%20These%20large%20files%20of%20data%20are%20processed%20by%20a%20Big%20Data%20solution%20on%20Azure.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

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!