Επεξεργασία

Κοινή χρήση μέσω


Query Event Grid subscriptions

This article describes how to list the Event Grid subscriptions in your Azure subscription. When querying your existing Event Grid subscriptions, it's important to understand the different types of subscriptions. You provide different parameters based on the type of subscription you want to get.

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

Resource groups and Azure subscriptions

Azure subscriptions and resource groups aren't Azure resources. Therefore, Event Grid subscriptions to resource groups or Azure subscriptions don't have the same properties as Event Grid subscriptions to Azure resources. Event Grid subscriptions to resource groups or Azure subscriptions are considered global.

To get Event Grid subscriptions for an Azure subscription and its resource groups, you don't need to provide any parameters. Make sure you've selected the Azure subscription you want to query. The following examples don't get Event Grid subscriptions for custom topics or Azure resources.

For Azure CLI, use:

az account set -s "My Azure Subscription"
az eventgrid event-subscription list

For PowerShell, use:

Set-AzContext -Subscription "My Azure Subscription"
Get-AzEventGridSubscription

To get Event Grid subscriptions for an Azure subscription, provide the topic type of Microsoft.Resources.Subscriptions.

For Azure CLI, use:

az eventgrid event-subscription list --topic-type-name "Microsoft.Resources.Subscriptions" --location global

For PowerShell, use:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Resources.Subscriptions"

To get Event Grid subscriptions for all resource groups within an Azure subscription, provide the topic type of Microsoft.Resources.ResourceGroups.

For Azure CLI, use:

az eventgrid event-subscription list --topic-type-name "Microsoft.Resources.ResourceGroups" --location global

For PowerShell, use:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Resources.ResourceGroups"

To get Event Grid subscriptions for a specified resource group, provide the name of the resource group as a parameter.

For Azure CLI, use:

az eventgrid event-subscription list --resource-group myResourceGroup --location global

For PowerShell, use:

Get-AzEventGridSubscription -ResourceGroupName myResourceGroup

Custom topics and Azure resources

Event Grid custom topics are Azure resources. Therefore, you query Event Grid subscriptions for custom topics and other resources, like Blob storage account, in the same way. To get Event Grid subscriptions for custom topics, you must provide parameters that identify the resource or identify the location of the resource. It's not possible to broadly query Event Grid subscriptions for resources across your Azure subscription.

To get Event Grid subscriptions for custom topics and other resources in a location, provide the name of the location.

For Azure CLI, use:

az eventgrid event-subscription list --location westus2

For PowerShell, use:

Get-AzEventGridSubscription -Location westus2

To get subscriptions to custom topics for a location, provide the location and the topic type of Microsoft.EventGrid.Topics.

For Azure CLI, use:

az eventgrid event-subscription list --topic-type-name "Microsoft.EventGrid.Topics" --location "westus2"

For PowerShell, use:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.EventGrid.Topics" -Location westus2

To get subscriptions to storage accounts for a location, provide the location and the topic type of Microsoft.Storage.StorageAccounts.

For Azure CLI, use:

az eventgrid event-subscription list --topic-type "Microsoft.Storage.StorageAccounts" --location westus2

For PowerShell, use:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Storage.StorageAccounts" -Location westus2

To get Event Grid subscriptions for a custom topic, provide the name of the custom topic and the name of its resource group.

For Azure CLI, use:

az eventgrid event-subscription list --topic-name myCustomTopic --resource-group myResourceGroup

For PowerShell, use:

Get-AzEventGridSubscription -TopicName myCustomTopic -ResourceGroupName myResourceGroup

To get Event Grid subscriptions for a particular resource, provide the resource ID.

For Azure CLI, use:

resourceid=$(az storage account show -g myResourceGroup -n myStorageAccount --query id --output tsv)
az eventgrid event-subscription list --resource-id $resourceid

For PowerShell, use:

$resourceid = (Get-AzResource -Name mystorage -ResourceGroupName myResourceGroup).ResourceId
Get-AzEventGridSubscription -ResourceId $resourceid

Next steps