az eventgrid event-subscription

Manage event subscriptions.

Manage event subscriptions for an Event Grid topic, domain, domain topic, Azure subscription, resource group or for any other Azure resource that supports event notifications.

Commands

az eventgrid event-subscription create Create a new event subscription.
az eventgrid event-subscription delete Delete an event subscription.
az eventgrid event-subscription list List event subscriptions.
az eventgrid event-subscription show Get the details of an event subscription.
az eventgrid event-subscription update Update an event subscription.

az eventgrid event-subscription create

Create a new event subscription.

az eventgrid event-subscription create --endpoint
--name
[--advanced-filter]
[--deadletter-endpoint]
[--endpoint-type {eventhub, hybridconnection, servicebusqueue, storagequeue, webhook}]
[--event-ttl]
[--expiration-date]
[--included-event-types]
[--labels]
[--max-delivery-attempts]
[--resource-group]
[--resource-id]
[--source-resource-id]
[--subject-begins-with]
[--subject-case-sensitive {false, true}]
[--subject-ends-with]
[--subscription]
[--topic-name]

Examples

Create a new event subscription for an Event Grid topic, using default filters.

az eventgrid event-subscription create --name es1 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Create a new event subscription for an Azure subscription subscription, using default filters.

az eventgrid event-subscription create --name es2 \
    --source-resource-id /subscriptions/{SubID} \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Create a new event subscription for a resource group, using default filters.

az eventgrid event-subscription create --name es3 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG} \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Create a new event subscription for a storage account, using default filters.

az eventgrid event-subscription create --name es3 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.Storage/storageaccounts/s1"  \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Create a new event subscription for a storage account, using advanced filters.

az eventgrid event-subscription create  --name es3 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.Storage/storageaccounts/s1" \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code
    --advanced-filter data.blobType StringIn BlockBlob
    --advanced-filter data.url StringBeginsWith https://myaccount.blob.core.windows.net

Create a new event subscription for an Azure subscription, with a filter specifying a subject prefix.

az eventgrid event-subscription create --name es4 \
    --source-resource-id /subscriptions/{SubID} \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code \
    --subject-begins-with mysubject_prefix

Create a new event subscription for a resource group, with a filter specifying a subject suffix.

az eventgrid event-subscription create --name es5 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG} \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code \
    --subject-ends-with mysubject_suffix

Create a new event subscription for an Azure subscription, using default filters, and an EventHub as a destination.

az eventgrid event-subscription create --name es2 \
    --source-resource-id /subscriptions/{SubID} \
    --endpoint-type eventhub \
    --endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.EventHub/namespaces/n1/eventhubs/EH1

Create a new event subscription for an Azure subscription, using default filters, and an Azure Storage queue as a destination.

az eventgrid event-subscription create --name es2 \
    --source-resource-id /subscriptions/{SubID} \
    --endpoint-type storagequeue \
    --endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/sa1/queueservices/default/queues/q1

Create a new event subscription for an Azure subscription, using default filters, and an Azure ServiceBusQueue as a destination.

az eventgrid event-subscription create --name es2 \
    --source-resource-id /subscriptions/{SubID} \
    --endpoint-type servicebusqueue \
    --endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/queues/queue1

Create a new event subscription for a storage account, with a deadletter destination and custom retry policy of maximum 10 delivery attempts and an Event TTL of 2 hours (whichever happens earlier).

az eventgrid event-subscription create --name es2 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.Storage/storageaccounts/s1" \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code \
    --deadletter-endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/s2/blobServices/default/containers/blobcontainer1 \
    --max-delivery-attempts 10 --event-ttl 120

Create a new event subscription for a domain topic.

az eventgrid event-subscription create --name es2 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/domain1/topics/t1" \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Create a new event subscription (for a storage account) with an expiration date.

az eventgrid event-subscription create --name es2 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.Storage/storageaccounts/sa1" \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code
    --expiration-date "2018-10-31"

Required Parameters

--endpoint

Endpoint where EventGrid should deliver events matching this event subscription. For webhook endpoint type, this should be the corresponding webhook URL. For other endpoint types, this should be the Azure resource identifier of the endpoint.

--name -n

Name of the event subscription.

Optional Parameters

--advanced-filter

An advanced filter enables filtering of events based on a specific event property.

--deadletter-endpoint

The Azure resource ID of an Azure Storage blob container destination where EventGrid should deadletter undeliverable events for this event subscription.

--endpoint-type

The type of the destination endpoint.

accepted values: eventhub, hybridconnection, servicebusqueue, storagequeue, webhook
default value: webhook
--event-ttl

Event time to live (in minutes). Must be a number between 1 and 1440.

default value: 1440
--expiration-date

Date or datetime (in UTC, e.g. '2018-11-30T11:59:59+00:00' or '2018-11-30') after which the event subscription would expire. By default, there is no expiration for the event subscription.

--included-event-types

A space-separated list of event types (e.g., Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted). To subscribe to all default event types, do not specify this argument. For event grid topics, event types are customer defined. For Azure events, e.g., Storage Accounts, IoT Hub, etc., you can query their event types using this CLI command 'az eventgrid topic-type list-event-types'.

--labels

A space-separated list of labels to associate with this event subscription.

--max-delivery-attempts

Maximum number of delivery attempts. Must be a number between 1 and 30.

default value: 30
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--resource-id

Fully qualified identifier of the Azure resource.

--source-resource-id

Fully qualified identifier of the Azure resource to which the event subscription needs to be created.

--subject-begins-with

An optional string to filter events for an event subscription based on a prefix. Wildcard characters are not supported.

--subject-case-sensitive

Specify to indicate whether the subject fields should be compared in a case sensitive manner. True if flag present.

accepted values: false, true
--subject-ends-with

An optional string to filter events for an event subscription based on a suffix. Wildcard characters are not supported.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--topic-name

Name of Event Grid topic.

az eventgrid event-subscription delete

Delete an event subscription.

az eventgrid event-subscription delete --name
[--resource-group]
[--resource-id]
[--source-resource-id]
[--subscription]
[--topic-name]

Examples

Delete an event subscription for an Event Grid topic.

az eventgrid event-subscription delete --name es1 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1

Delete an event subscription for an Event Grid domain topic.

az eventgrid event-subscription delete --name es1 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/domain1/topics/topic1

Delete an event subscription for an Event Grid domain.

az eventgrid event-subscription delete --name es1 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/domain1

Delete an event subscription for an Azure subscription.

az eventgrid event-subscription delete --name es2 \
    --source-resource-id /subscriptions/{SubID}

Delete an event subscription for a resource group.

az eventgrid event-subscription delete --name es3 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}

Delete an event subscription for a storage account.

az eventgrid event-subscription delete --name es3 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/microsoft.storage/storageaccounts/kalsegblob

Required Parameters

--name -n

Name of the event subscription.

Optional Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--resource-id

Fully qualified identifier of the Azure resource.

--source-resource-id

Fully qualified identifier of the Azure resource whose event subscription needs to be deleted.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--topic-name

Name of Event Grid topic.

az eventgrid event-subscription list

List event subscriptions.

az eventgrid event-subscription list [--location]
[--odata-query]
[--resource-group]
[--resource-id]
[--source-resource-id]
[--subscription]
[--topic-name]
[--topic-type-name]

Examples

List all event subscriptions created for an Event Grid topic.

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1

List all event subscriptions created for a storage account.

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.Storage/storageaccounts/kalsegblob

List all event subscriptions created for an Azure subscription.

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}

List all event subscriptions created for a resource group.

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}

List all event subscriptions for an Event Grid domain.

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/d1

List all event subscriptions for an Event Grid domain topic.

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/d1/topics/topic1

List all Storage event subscriptions (under the currently selected Azure subscription) in westus2.

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

List all Storage event subscriptions (under the given resource group) in westus2.

az eventgrid event-subscription list --topic-type Microsoft.Storage.StorageAccounts --location westus2 --resource-group {RG}

List all regional or global event subscriptions (under the currently selected Azure subscription).

az eventgrid event-subscription list --location westus2
az eventgrid event-subscription list --location global

List all regional or global event subscriptions under a specified resource group.

az eventgrid event-subscription list --location westus2 --resource-group {RG}
az eventgrid event-subscription list --location global --resource-group {RG}

List all event subscriptions for an Event Grid domain whose name contains the pattern "XYZ"

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/d1 --odata-query "Contains(name, 'XYZ')"

List all event subscriptions for an Event Grid domain except the event subscription with name "name1"

az eventgrid event-subscription list --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/domains/d1 --odata-query "NOT (name eq 'name1')"

Optional Parameters

--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

--odata-query

The OData query used for filtering the list results. Filtering is currently allowed on the Name property only. The supported operations include: CONTAINS, eq (for equal), ne (for not equal), AND, OR and NOT.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--resource-id

Fully qualified identifier of the Azure resource.

--source-resource-id

Fully qualified identifier of the Azure resource whose event subscription needs to be listed.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--topic-name

Name of Event Grid topic.

--topic-type-name

Name of the topic-type whose event subscriptions need to be listed. When this is specified, you must also specify --location.

az eventgrid event-subscription show

Get the details of an event subscription.

az eventgrid event-subscription show --name
[--include-full-endpoint-url {false, true}]
[--resource-group]
[--resource-id]
[--source-resource-id]
[--subscription]
[--topic-name]

Examples

Show the details of an event subscription for an Event Grid topic.

az eventgrid event-subscription show --name es1 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/rg1/providers/Microsoft.EventGrid/topics/topic1

Show the details of an event subscription for an Azure subscription.

az eventgrid event-subscription show --name es2 \
    --source-resource-id /subscriptions/{SubID}

Show the details of an event subscription for a resource group.

az eventgrid event-subscription show --name es3 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/rg1

Show the details of an event subscription for a storage account.

az eventgrid event-subscription show --name es3 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/rg1/providers/microsoft.storage/storageaccounts/kalsegblob

Required Parameters

--name -n

Name of the event subscription.

Optional Parameters

--include-full-endpoint-url

Specify to indicate whether the full endpoint URL should be returned. True if flag present.

accepted values: false, true
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--resource-id

Fully qualified identifier of the Azure resource.

--source-resource-id

Fully qualified identifier of the Azure resource whose event subscription needs to be shown.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--topic-name

Name of Event Grid topic.

az eventgrid event-subscription update

Update an event subscription.

az eventgrid event-subscription update --name
[--add]
[--deadletter-endpoint]
[--endpoint]
[--endpoint-type {eventhub, hybridconnection, servicebusqueue, storagequeue, webhook}]
[--force-string]
[--included-event-types]
[--labels]
[--remove]
[--resource-group]
[--resource-id]
[--set]
[--source-resource-id]
[--subject-begins-with]
[--subject-ends-with]
[--subscription]
[--topic-name]

Examples

Update an event subscription for an Event Grid topic to specify a new endpoint.

az eventgrid event-subscription update --name es1 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Update an event subscription for an Azure subscription to specify a new subject-ends-with filter.

az eventgrid event-subscription update --name es2 \
    --source-resource-id /subscriptions/{SubID} \
    --subject-ends-with .jpg

Update an event subscription for a resource group to specify a new endpoint and a new subject-ends-with filter.

az eventgrid event-subscription update --name es3 \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG} \
    --subject-ends-with .png \
    --endpoint https://contoso.azurewebsites.net/api/f1?code=code

Update an event subscription for a storage account to specify a new list of included event types.

az eventgrid event-subscription update --name es3 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/microsoft.storage/storageaccounts/kalsegblob" \
    --included-event-types Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted

Update an event subscription for a storage account, to include a deadletter destination.

az eventgrid event-subscription update --name es2 \
    --source-resource-id "/subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.Storage/storageaccounts/kalsegblob" \
    --deadletter-endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.Storage/storageAccounts/sa1/blobServices/default/containers/blobcontainer1

Required Parameters

--name -n

Name of the event subscription.

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty <key=value, string or JSON string>.

--deadletter-endpoint

The Azure resource ID of an Azure Storage blob container destination where EventGrid should deadletter undeliverable events for this event subscription.

--endpoint

Endpoint where EventGrid should deliver events matching this event subscription. For webhook endpoint type, this should be the corresponding webhook URL. For other endpoint types, this should be the Azure resource identifier of the endpoint.

--endpoint-type

The type of the destination endpoint.

accepted values: eventhub, hybridconnection, servicebusqueue, storagequeue, webhook
default value: webhook
--force-string

When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.

--included-event-types

A space-separated list of event types (e.g., Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted). To subscribe to all default event types, do not specify this argument. For event grid topics, event types are customer defined. For Azure events, e.g., Storage Accounts, IoT Hub, etc., you can query their event types using this CLI command 'az eventgrid topic-type list-event-types'.

--labels

A space-separated list of labels to associate with this event subscription.

--remove

Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--resource-id

Fully qualified identifier of the Azure resource.

--set

Update an object by specifying a property path and value to set. Example: --set property1.property2=.

--source-resource-id

Fully qualified identifier of the Azure resource whose event subscription needs to be updated.

--subject-begins-with

An optional string to filter events for an event subscription based on a prefix. Wildcard characters are not supported.

--subject-ends-with

An optional string to filter events for an event subscription based on a suffix. Wildcard characters are not supported.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--topic-name

Name of Event Grid topic.