0

I have successfully created an event trigger on storage blob creation, on a storage account called receivingtestwesteurope, under resource group omni-test, which is received via a function called ValidateMetadata. I created this via the portal GUI. However I now want to add deadletter/retry policies, which can only be done via the CLI.

The working trigger is like this:

{
    "destination": {
      "endpointBaseUrl": "https://omnireceivingprocesstest.azurewebsites.net/admin/extensions/EventGridExtensionConfig",
      "endpointType": "WebHook",
      "endpointUrl": null
    },
    "filter": {
      "includedEventTypes": [
        "Microsoft.Storage.BlobCreated"
      ],
      "isSubjectCaseSensitive": null,
      "subjectBeginsWith": "/blobServices/default/containers/snapshots/blobs/",
      "subjectEndsWith": ".png"
    },
    "id": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/Microsoft.Storage/StorageAccounts/receivingtestwesteurope/providers/Microsoft.EventGrid/eventSubscriptions/png",
    "labels": [
      ""
    ],
    "name": "png",
    "provisioningState": "Succeeded",
    "resourceGroup": "omni-test",
    "topic": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope",
    "type": "Microsoft.EventGrid/eventSubscriptions"
}

First I thought I could update the existing event with a deadletter queue:

az eventgrid event-subscription update --name png --deadletter-endpoint receivingtestwesteurope/blobServices/default/containers/eventgrid

Which returns:

az: error: unrecognized arguments: --deadletter-endpoint receivingtestwesteurope/blobServices/default/containers/eventgrid

Then I tried via REST Patch:

https://learn.microsoft.com/en-us/rest/api/eventgrid/eventsubscriptions/update

  • scope: /subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope
  • eventSubscriptionName: png
  • api-version: 2018-05-01-preview

Body:

"deadletterdestination": {
  "endpointType": "StorageBlob",
  "properties": {
    "blobContainerName": "eventgrid",
    "resourceId": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope"
  }}

Which returns

"Model state is invalid."

===================

Final working solution:

{
    "deadletterdestination": {
        "endpointType": "StorageBlob",
        "properties": {
            "blobContainerName": "eventgrid",
            "resourceId": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope"
        }
    }
}
Red Riding Hood
  • 1,932
  • 1
  • 17
  • 36
  • That's great. There is a bad news for dead-lettering, such as a turning-off dead-lettering. I have mentioned many times to MS Event Grid team and the response is the following, you can not use a Patch, you have to use multiple requests such as GET subscription, Get full destinationEndpointUrl and then recreating this event subscription without the deadLetterDestination property using a PUT request. I think, this is a bug. In other words, we can NOT use a simple removing property such as "deadletterdestination":null – Roman Kiss Aug 01 '18 at 18:18

1 Answers1

3

have a look at Manage Event Grid delivery settings, where in details is described turning-on a dead-lettering. Note, you have to install an eventgrid extension

az extension add --name eventgrid

also, you can use a REST API for updating your event subscription for dead-lettering.

besides that, I have just released my tinny tool Azure Event Grid Tester for helping with an Azure Event Grid model on the local machine.

Update:

The following is a deadletterdestination property:

"deadletterdestination": {
  "endpointType": "StorageBlob",
  "properties": {
    "blobContainerName": "{containerName}",
    "resourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resgroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}"
   }
 }

you can use the Event Subscriptions - Update (REST API PATCH) with the above property. Note, that the api-version=2018-05-01-preview must be used.

Roman Kiss
  • 7,925
  • 1
  • 8
  • 21
  • The commands I'm having trouble with are from the first link you provided – Red Riding Hood Jul 31 '18 at 12:34
  • I have just installed on my azure portal cloud shell (>_) this eventgrid extension. The response is: The installed extension 'eventgrid' is in preview., so did you have the problem with this installation? – Roman Kiss Jul 31 '18 at 12:45
  • Hi, your update looks really useful. I feel this is close, I updated my question with my progress. I ran the REST patch via the online editor – Red Riding Hood Jul 31 '18 at 13:46
  • 1
    the patch (update) is working only for properties, so the json body must be in the format: { "deadletterdestination": { …. }, "filter": {}, "labels":[ ], ... } , please have a look at my Update, I am going to edit it. Thanks – Roman Kiss Jul 31 '18 at 15:18
  • The EventSubscriptions REST API (including `Update` method) url (https://learn.microsoft.com/en-us/rest/api/eventgrid/eventsubscriptions/update) is dead (404). Anyone know what the updated URL is? – ericOnline May 27 '21 at 19:07