az eventgrid event-subscription

Manage event subscriptions for an Event Grid topic or for an Azure resource.

Manage event subscriptions for an Event Grid 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 for an Event Grid topic or for an Azure resource.
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 for an Event Grid topic or for an Azure resource.

az eventgrid event-subscription create --endpoint
--name
[--deadletter-endpoint]
[--endpoint-type {eventhub, hybridconnection, storagequeue, webhook}]
[--event-ttl]
[--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 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 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

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

--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, storagequeue, webhook
default value: webhook
--event-ttl

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

default value: 1440
--included-event-types

A space-separated list of event types. Example: Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted. To subscribe to all event types, the string "All" should be specified.

--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 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]
[--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 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}

Optional Parameters

--location -l

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

--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, 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, 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. Example: Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted. To subscribe to all event types, the string "All" should be specified.

--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.