0
votes

Trying to create an event subscription using the CLI.

Using the portal, there are seven different endpoint types:

  • Azure Function
  • Web Hook
  • Storage Queues
  • Event Hubs
  • Hybrid Connections
  • Service Bus Queue
  • Service Bus Topic

Using the CLI, at least in the documentation, only three are available:

  • eventhub
  • hybridconnection
  • servicebusqueue
  • storagequeue
  • webhook

How to create an event subscription pointing to an Azure Function like it is done in the portal? I know that as a workaround I can use the function as a WebHook, but it is not the same.

Az version:

$ az --version
azure-cli                          2.7.0

command-modules-nspkg              2.0.3
core                               2.7.0
nspkg                              3.0.4
telemetry                          1.0.4

Extensions:
interactive                        0.4.4

Python location '/opt/az/bin/python3'
Extensions directory '/home/angelcc/.azure/cliextensions'

Python (Linux) 3.6.10 (default, May 29 2020, 08:10:59) 
[GCC 9.3.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

Please let us know how we are doing: https://aka.ms/clihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
1

1 Answers

0
votes

use the following example:

  az eventgrid event-subscription create --name myName \
      --source-resource-id "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRG/providers/Microsoft.EventGrid/topics/myTopic" \
      --endpoint-type AzureFunction \
      --endpoint "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRG1/providers/Microsoft.Web/sites/myFncApp/functions/myEventGridTrigger"

UPDATE:

In the case of avoiding the eventgrid extension, we can use a native access to the AEG service such as REST API.

The following is the above example using the az rest:

az rest --method PUT \
  --url "https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRG/providers/Microsoft.EventGrid/topics/myTopic/providers/Microsoft.EventGrid/eventSubscriptions/myName?api-version=2020-04-01-preview" \
  --body "{\"properties\":{\"destination\":{\"endpointType\":\"AzureFunction\",\"properties\":{\"resourceId\":\"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myRG1/providers/Microsoft.Web/sites/myFncApp/functions/myEventGridTrigger\"}}}}"