Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Storage event triggers - capturing a blob being deleted

I'm investigating the webhooks / event triggers available for Azure Storage. Unfortunately the documentation seems preoccupied with showing how to get the Azure portal to build the function for me, which doesn't permit local testing.

In particular, I'm looking into capturing when a blob has been deleted.

Example of my usage (an Azure Function):

[FunctionName("BlobDelete")]
public static async Task Run([BlobTrigger("...")]
                             CloudBlockBlob blob,
                             string name,
                             TraceWriter log)
{
    ;
}

The problem arises when I delete a blob from the storage container: the function is not triggered.

However, I found that if I hit CTRL+C in the console then the function is triggered.

Can anyone explain why? Is my usage wrong?

Also, I was unable to find any documentation for the BlobDelete trigger, I could only find BlobInput, BlobOutput and BlobCopy. I took a guess with BlobDelete and it... half works.

like image 651
awj Avatar asked Jan 24 '26 10:01

awj


2 Answers

The BlobTrigger does not fire on deleted blobs, just on new / modified blobs.

Alternatives include (listed in recommended order):

  1. Check out the new (Still in preview) Event Grid notification system for blob events: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-event-quickstart . This will give you webhooks for blob events.
  2. switch the problem over to a Queue Trigger and queue a message when the blob is deleted (if you can control it)
  3. take a manual approach - like scanning the directory on a timer trigger. This may not be feasible in cases where you have large containers or don't have state to know that the blob previously existed. But it works great in "garbage collector" scenarios.
like image 168
Mike S Avatar answered Jan 26 '26 00:01

Mike S


Blob Trigger does not react on deleted blobs. If you need that, you should have a look at Event Grid trigger with blog events.

like image 24
Mikhail Shilkov Avatar answered Jan 25 '26 23:01

Mikhail Shilkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!