0

Azure Function is not being called for deleted blobs. I am referring sample code - https://learn.microsoft.com/bs-latn-ba/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp

Below is the sample code -

[FunctionName("BlobTriggerCSharp")] public static void Run([BlobTrigger("samples-workitems/{name}")] Stream myBlob, string name, ILogger log) { log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); }

Expected behavior

Azure Functions Blob storage trigger (azure function) should be fired (called) when the blob is deleted from the container

Actual behavior

Azure Functions Blob storage trigger (azure function) is not being fired (called) when the blob is deleted from the container

I am using the latest Package - Microsoft.Azure.WebJobs.Extensions.Storage (version - 4.0.2)

Can someone please help me?

Thanks, Sanjay

sanjay kulkarni
  • 197
  • 2
  • 13

1 Answers1

1

As you see here, that this way you will be able to create a function app that runs when a blob is added to or updated in Blob storage.

You might want to use Event Grid Triggers for this scenario. These events are triggered when a client creates, replaces, or deletes a blob by calling Blob REST APIs.

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
  • Thank you so much for the quick response. Actually my requirement is, whenever the user is uploading new/modifying/deleting files/blobs thru REST API calls, I want to store the entire custom audit trail chain on each file (e.g. user name, last modified time etc.). I am using **Blob metadata** to do that. But it only saves the current state of the object/blob, not the whole history if the user is taking multiple actions on the same file. I believe by using the **Event Grid Trigger** will be overkill. Can you please point out the correct way? – sanjay kulkarni Sep 06 '20 at 13:23
  • 1
    It is written "The Blob storage trigger starts a function when a new or updated blob is detected." here - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp. So, you cannot get deleted events in Blob trigger. Alternative for you is only to use Event Grid so that you get deleted events of blobs as well. In fact, Event Grid Triggers are faster than Blob triggers - https://www.youtube.com/watch?v=0sEzimJYhME. Pricing: https://azure.microsoft.com/en-in/pricing/details/event-grid/. It also won't require new code addition in your function app. – Harshita Singh Sep 06 '20 at 16:19
  • Thank you Harshita.. How to get metadata of deleted blob in Event Grid Trigger Azure Function? Can you please also let me know? Below is a sample code -> [FunctionName("EventGridTriggerFunction")] public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log) { log.LogInformation(eventGridEvent.Data.ToString()); }} – sanjay kulkarni Sep 08 '20 at 08:48
  • What do you get in `eventGridEvent`? – Harshita Singh Sep 08 '20 at 18:47
  • I don't get any blob's metadata in the "data" object/property. Is there any alternate way? – sanjay kulkarni Sep 09 '20 at 10:00
  • Actually we can't retrieve deleted blob's metadata using BlobClient. I receives 404 error - blob not found. Even though we can't set metadata while deleting blob using REST API Delete call. I don't know why there are limitations. And also no way to do custom audit log. Please let me know if you find anything related to achieve this. Thanks – sanjay kulkarni Sep 10 '20 at 18:28
  • Yea, you can create a GitHub issue for this referencing https://learn.microsoft.com/en-us/azure/event-grid/event-schema-blob-storage document. – Harshita Singh Sep 10 '20 at 20:23