Event Grid サブスクリプションのクエリを実行する

この記事では、Azure サブスクリプション内の Event Grid サブスクリプションの一覧を表示する方法を説明します。 既存の Event Grid サブスクリプションのクエリを実行するときは、サブスクリプションの種類を理解しておく必要があります。 取得するサブスクリプションの種類に基づいて、異なるパラメーターを指定します。

Note

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

リソース グループと Azure サブスクリプション

Azure サブスクリプションとリソース グループは、Azure リソースではありません。 そのため、リソース グループまたは Azure サブスクリプションに対する Event Grid サブスクリプションには、Azure リソースに対する Event Grid サブスクリプションと同じプロパティはありません。 リソース グループまたは Azure サブスクリプションに対する Event Grid サブスクリプションは、グローバルと見なされます。

Azure サブスクリプションとそのリソース グループに対する Event Grid サブスクリプションを取得するには、どのようなパラメータも指定する必要はありません。 クエリを実行する Azure サブスクリプションを選択したことを確認してください。 次の例では、カスタム トピックまたは Azure リソースに対する Event Grid サブスクリプションは取得しません。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

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

Azure サブスクリプションに対する Event Grid サブスクリプションを取得するには、トピックの種類 Microsoft.Resources.Subscriptions を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

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

Azure サブスクリプション内のすべてのリソース グループに対する Event Grid サブスクリプションを取得するには、トピックの種類 Microsoft.Resources.ResourceGroups を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

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

指定したリソース グループに対する Event Grid サブスクリプションを取得するには、パラメータとしてリソース グループの名前を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

Get-AzEventGridSubscription -ResourceGroupName myResourceGroup

カスタム トピックと Azure リソース

Event Grid のカスタム トピックは Azure リソースです。 そのため、カスタム トピックと、Blob Storage アカウントなどのほかのリソースでは、Event Grid サブスクリプションのクエリを実行する方法は同じです。 カスタム トピックに対する Event Grid サブスクリプションを取得するには、リソースまたはリソースの場所を示すパラメータを指定する必要があります。 Azure サブスクリプション全体のリソースに対して Event Grid サブスクリプションのクエリをグローバルに実行することはできません。

1 つの場所のカスタム トピックとほかのリソースに対する Event Grid サブスクリプションを取得するには、場所の名前を指定します。

Azure CLI では、次を使用します。

az eventgrid event-subscription list --location westus2

PowerShell では、次を使用します。

Get-AzEventGridSubscription -Location westus2

ある場所のカスタム トピックに対するサブスクリプションを取得するには、場所とトピックの種類 Microsoft.EventGrid.Topics を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

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

ある場所のストレージ アカウントに対するサブスクリプションを取得するには、場所とトピックの種類 Microsoft.Storage.StorageAccounts を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

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

カスタム トピックに対する Event Grid サブスクリプションを取得するには、カスタム トピックの名前とそのリソース グループの名前を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

Get-AzEventGridSubscription -TopicName myCustomTopic -ResourceGroupName myResourceGroup

特定のリソースの Event Grid サブスクリプションを取得するには、リソース ID を指定します。

Azure CLI では、次を使用します。

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

PowerShell では、次を使用します。

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

次のステップ