azure-functionsazure-eventgridadvanced-filter

Azure EventGrid Advanced Filter where Subject does not contain string


Scenario:

Key: Subject

Operator: String ends with

Value: .txt, .json etc.

enter image description here

I now need to filter which Blob Containers trigger an EventGrid message.

Sample EventGrid Subject:

"subject": "/blobServices/default/containers/vnd-test/blobs/sample.zip"

How do I use EventGrid Advanced Filters to NOT TRIGGER when blobs are uploaded to vnd-test container?

Tried:

Key: Subject

Operator: String is not in

Value: vnd-test

But the EventGrid message still fires and triggers the Function.

Ideas?

enter image description here


Solution

  • How do I use EventGrid Advanced Filters to NOT TRIGGER when blobs are uploaded to vnd-test container?

    I know what you want to do, but now there is no corresponding operatorto implement your idea in the event grid.

    I can briefly explain to you why the event grid does not refuse to receive events sent to the vnd-test container.

    The structure of blob created event is like below:

    [{
      "topic": "/subscriptions/{subscription-id}/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/my-storage-account",
      "subject": "/blobServices/default/containers/test-container/blobs/new-file.txt",
      "eventType": "Microsoft.Storage.BlobCreated",
      "eventTime": "2017-06-26T18:41:00.9584103Z",
      "id": "831e1650-001e-001b-66ab-eeb76e069631",
      "data": {
        "api": "PutBlockList",
        "clientRequestId": "6d79dbfb-0e37-4fc4-981f-442c9ca65760",
        "requestId": "831e1650-001e-001b-66ab-eeb76e000000",
        "eTag": "\"0x8D4BCC2E4835CD0\"",
        "contentType": "text/plain",
        "contentLength": 524288,
        "blobType": "BlockBlob",
        "url": "https://my-storage-account.blob.core.windows.net/testcontainer/new-file.txt",
        "sequencer": "00000000000004420000000000028963",
        "storageDiagnostics": {
          "batchId": "b68529f3-68cd-4744-baa4-3c0498ec19f0"
        }
      },
      "dataVersion": "",
      "metadataVersion": "1"
    }]
    

    When you set subject string is not in ["vnd-test"], in fact it is doing:

    For example, if a file named 111.txt been sended to vnd-test. It conducts the following thought process:

    1, Is /blobServices/default/containers/vnd-test/111.txt one of the elements of the collection ["vnd-test"]?

    2, No, it is not. That is great! I will accept this event because it meets the condition.

    3, event grid was very happy to create the blobcreated event and send this event to the function endpoint, so your function is triggered

    It does not compare part of the string inside the subject with vnd-test, but uses the entire subject to compare with vnd-test. However, the subject is refined to the blob level, how can it be possible to write every possible blob to the collection? The current operator does not support your idea.