1
votes

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.

2

2 Answers

4
votes

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://docs.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.
3
votes

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