0

I am using event grid for my web api. The domain name of my api have changed and now I need to update all event grid subscriptions. It so happends that I have Azure CLI command to create each subscription, so the easiest way would be to delete all of them and create new ones. I have checked the docs but az eventgrid event-subscription delete command requires --name parameter which means that I need to execute this manually for each subscriptions. While this is not a huge problem it would require to maintain second command list for deleting. It would be much faster if I could simply say --all or something similar.

Maybe there is a solution to delete all event grid subscriptions without too much of o hassle?

My ideas so far:

  • Drop entire event grid topic and create new one (seems a bit excessive)
  • Apply some bash magic with az eventgrid event-subscription list
Ramūnas
  • 1,494
  • 18
  • 37

1 Answers1

1

According to my test, we can use the following command to delete a list of subscriptions that are associated with Azure event gird topic in Azure Cloud Shell.

results=$(az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/domain1/topics/topic1 --query "[].{Name:name}")


for row in $(echo "$results" | jq -r '.[]|"\(.Name)"')
do
  az eventgrid event-subscription delete --name $row --source-resource-id  /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/domain1/topics/topic1
done

enter image description here

Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • In the case, where the *source-resource-id* is a **domain topic**, we don't need to walk through the list of the subscriptions and individually delete one by one. Instead of this loop we can delete a *domain topic* (the source of interest). Note, that the last deleted subscription in the loop process will delete also a domain topic, anyway. This is a unique case in the AEG eventing model, where the domain topic can be created by the consumer side (by subscription). – Roman Kiss Dec 12 '19 at 08:57