如何使用 CLI 创建具有 enpoint 类型 Azure Function 的事件订阅?

How to create an event subscription with enpoint type Azure Function using the CLI?

正在尝试使用 CLI 创建事件订阅。

使用门户,有七种不同的端点类型:

使用 CLI,至少在文档中,只有三个可用:

如何创建指向 Azure 函数的事件订阅就像在门户中完成的那样?我知道作为一种解决方法,我可以将该函数用作 WebHook,但它不一样。

A​​z 版本:

$ 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

使用以下示例:

  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"

更新:

在避免eventgrid扩展的情况下,我们可以使用原生访问AEG服务,例如REST API

下面是上面使用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\"}}}}"