查询事件网格订阅Query Event Grid subscriptions

本文介绍了如何列出 Azure 订阅中的事件网格订阅。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.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

资源组和 Azure 订阅Resource groups and Azure subscriptions

Azure 订阅和资源组不是 Azure 资源。Azure subscriptions and resource groups aren't Azure resources. 因此,对资源组或 Azure 订阅的事件网格订阅不具有与对 Azure 资源的事件网格订阅相同的属性。Therefore, event grid subscriptions to resource groups or Azure subscriptions do not have the same properties as event grid subscriptions to Azure resources. 对资源组或 Azure 订阅的事件网格订阅被视为全局的。Event grid subscriptions to resource groups or Azure subscriptions are considered global.

若要获取对 Azure 订阅及其资源组的事件网格订阅,不需要提供任何参数。To get event grid subscriptions for an Azure subscription and its resource groups, you don't need to provide any parameters. 请确保已选择要查询的 Azure 订阅。Make sure you've selected the Azure subscription you want to query. 以下示例不会获取对自定义主题或 Azure 资源的事件网格订阅。The following examples don't get event grid subscriptions for custom topics or Azure resources.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用:For PowerShell, use:

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

若要获取对 Azure 订阅的事件网格订阅,请提供主题类型 Microsoft.Resources.SubscriptionsTo get event grid subscriptions for an Azure subscription, provide the topic type of Microsoft.Resources.Subscriptions.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用:For PowerShell, use:

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

若要获取对 Azure 订阅内的所有资源组的事件网格订阅,请提供主题类型 Microsoft.Resources.ResourceGroupsTo get event grid subscriptions for all resource groups within an Azure subscription, provide the topic type of Microsoft.Resources.ResourceGroups.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用: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.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用:For PowerShell, use:

Get-AzEventGridSubscription -ResourceGroupName myResourceGroup

自定义主题和 Azure 资源Custom topics and Azure resources

事件网格自定义主题是 Azure 资源。Event grid custom topics are Azure resources. 因此,可以采用相同的方式查询对自定义主题和其他资源(例如 Blob 存储帐户)的事件网格订阅。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. 不能在整个 Azure 订阅中广泛地查询对资源的事件网格订阅。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.

对于 Azure CLI,请使用:For Azure CLI, use:

az eventgrid event-subscription list --location chinaeast

对于 PowerShell,请使用:For PowerShell, use:

Get-AzEventGridSubscription -Location chinaeast

若要为某个位置获取对自定义主题的订阅,请提供该位置和主题类型 Microsoft.EventGrid.TopicsTo get subscriptions to custom topics for a location, provide the location and the topic type of Microsoft.EventGrid.Topics.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用:For PowerShell, use:

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

若要为某个位置获取对存储帐户的订阅,请提供该位置和主题类型 Microsoft.Storage.StorageAccountsTo get subscriptions to storage accounts for a location, provide the location and the topic type of Microsoft.Storage.StorageAccounts.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用:For PowerShell, use:

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

若要获取对某个自定义主题的事件网格订阅,请提供该自定义主题的名称及其资源组的名称。To get event grid subscriptions for a custom topic, provide the name of the custom topic and the name of its resource group.

对于 Azure CLI,请使用:For Azure CLI, use:

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

对于 PowerShell,请使用:For PowerShell, use:

Get-AzEventGridSubscription -TopicName myCustomTopic -ResourceGroupName myResourceGroup

若要获取对特定资源的事件网格订阅,请提供资源 ID。To get event grid subscriptions for a particular resource, provide the resource ID.

对于 Azure CLI,请使用:For Azure CLI, use:

resourceid=$(az resource show -n mystorage -g myResourceGroup --resource-type "Microsoft.Storage/storageaccounts" --query id --output tsv)
az eventgrid event-subscription list --resource-id $resourceid

对于 PowerShell,请使用:For PowerShell, use:

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

后续步骤Next steps