Azure event gird-blob created trigger in logic apps

Amar-Azure-Practice 656 Reputation points
2021-02-27T21:41:42.017+00:00

Hi,

I am using the azure event grid with blob created event in logic app, When i create a new blob in storage account , i can see the logic app is triggering , in the event data i can not see the file name.
and i can see 3 events occurred when one blob is created.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,862 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
319 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 68,656 Reputation points
    2021-03-01T05:01:27.13+00:00

    Hi @Amar-Azure-Practice

    If you look into the example events for Microsoft.Storage.BlobCreated event you will get below output with the action when a resource event occurs

    {  
      "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"  
    }  
    

    In the above output, you can find the blob path or the file name either using the subject or the url field. You can use the below expression in your logicapp

    last(split(triggerBody()?['subject'],'/')) --> To get the fileName

    last(split(triggerBody()?['subject'],'/blobs/')) --> To get the blob path

    You need to modify the above expression according to your business needs.

    72769-image.png

    I have tested the setup and I see only one logic app trigger for each blob created. If you have multiple files in the folder when you have tested then the logic app will be trigger multiple times. Please navigate to the run history of your logic app and verify the subject of the output response. If you see a different subject for different run ID's then that the run was triggered for different blobs.

    Update:

    I have tested the scenario with logic app (preview) and it is working as expected.

    Using the output of "When a resource event occurs" I have defined a variable and assign the value as below

    74040-image.png

    In the below screenshot you can see the correct value for the blob filename that I have uploaded.

    74077-image.png

    74083-image.png

    Update: 3/5

    @Amar-Azure-Practice I have tested the scenario and it is working as expected. I believe the three logs that you are talking about is the Validation event that was triggered. Please verify the output of all three triggers if the eventType": "Microsoft.EventGrid.SubscriptionValidationEvent" and the subject will be empty for this event. You need to verify events with Microsoft.Storage.BlobCreated if you are not able to see these events then first verify if the storage account that you have configured is of type StorageV2 (general purpose v2), BlockBlobStorage, and BlobStorage that support event integration. If you are using the right storage account then navigate to Events under the storage account and verify if there are any event grid subscriptions created successfully and the endpoint will be your logic app event grid trigger URL.

    {  
      "id": "871ecfe7-c036-4ef7-ab6a-8f0da9e22c64",  
      "topic": "/subscriptions/<subscrptionID>/resourceGroups/<resourcegroup>/providers/Microsoft.Storage/storageAccounts/<storage account>",  
      "subject": "",  
      "data": {  
        "validationCode": "F1C41DA2-D1B3-49C3-8357-05827058013A"  
      },  
      "eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",  
      "eventTime": "2021-03-05T04:54:08.9247871Z",  
      "metadataVersion": "1",  
      "dataVersion": "2"  
    }  
    

    74635-image.png

    Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.