Azure Logic Apps | Event Grid & Azure Functions : Use case

Amine Charot
Charot
Published in
4 min readMay 13, 2019

Hello, recently, we have heard a lot about Azure Logic Apps and Azure Functions. I’ve written an article about Azure Logic Apps and I’ve done an example about it and how we can use it and take benefit of it in case of a continuous deployment of an infrastructure.

Let’s see, how Azure Logic Apps goes well with Azure Functions and Azure Event Grid.

  • Azure Event Grid

Azure Event Grid is a cloud service that provides Event-Driven Computing. It’s an easy service that allows us to create application based on what happened (Events).

Event Grid has a support of many Azure services such as Azure Storage Blobs, Resource Groups and too many others. It also supports your own events.

How to protect Storage Account Blobs

Sometimes, you may have some important blobs in your storage account. These blobs should not be deleted otherwise it will cause a downtime in your production environment.

I was thinking by saying this about Azure Batch Account. Actually, it may use Application Manager which needs to communicate with your storage account so it can get binaries. If it does not find the referenced version inside the Storage Account, the compute node will fail to start, it will be unusable. Same thing with Start Task, which may use resource files referenced in a Storage Account. If it does not exist, the compute node will be in a “Failed to start task” state.

An idea to prevent this, is to use a backup.

The idea is that when you push something inside the main storage, you should push it inside the backup one. So if one day, somehow, the blob is deleted, you will find a backup.

Instead of copying the blob manually (I always talk about automation), we may use Azure Logic Apps, Event Grid and Functions, to copy and realize a lot of other things like sending an email, trigger some sanity checks ...

By deleting a blob, we send a deletion event through Azure Event Grid. It will trigger the Logic App which will run a Function that will log and copy the binaries from the backup to the main storage and send an email.

The Function will write a log inside Application Insights. So we know when and what happened (As I said once, the logs are so important for a DevOps). Then, it will copy the blob from the backup storage to the main one.

For the keys, I suggest you to use Azure Key Vault to keep them safe, to automate and make your Function more flexible.

Azure Logic Apps workflow should be as following :

This means, when an event occurs, run my Function called “HttpTrigger1”. I specified the wanted event inside the trigger :

This event will return a body that contains information about what I’ve deleted :

This body is used by the Function to get to which blob we should copy and what was deleted.

var destinationStorageAccountName = storage.Host.Split(".").First();    var containerName = storage.PathAndQuery.Split("/")[1];    
var blobName = storage.PathAndQuery.Split("/").Last();

Unfortunately, I did not find how we can detect who deletes the blob. Thanks to Application Insights, we have the deletion event logged :

It was just an use case where I’ve tried to explain how we can use Azure Event Grid and Azure Logic Apps with Azure Functions.

This may be useful to protect Resource Groups too. If a resource group is deleted, you may trigger Azure Logic Apps which will run a Function to check, get more information and log the resource deleted, then deploy again the resource group using Azure Logic Apps as I’ve shown you in : Deploy ARM Templates using Azure Logic Apps & API Management.

Bella ciao,

--

--