我正在尝试使用ARM模板在Azure存储帐户上创建Eventgrid订阅。在门户中手动创建它并进入高级设置,产生了以下模板。我进一步向其中添加了所需的模板项目(例如架构),但它始终会产生错误。我尝试过在线寻找相似的模板,但是似乎无法使用"endpointType": "AzureFunction"
找到任何模板。同样,在资源浏览器中也没有提到可以进一步帮助我的部署。
任何人都可以帮助我解决问题吗?
在创建过程中从门户网站生成的模板:
{
"name": "test123",
"properties": {
"topic": "/subscriptions/<guid>/resourceGroups/<myGroup>/providers/Microsoft.Storage/storageAccounts/<myStorageAccount>",
"destination": {
"endpointType": "AzureFunction",
"properties": {
"resourceId": "/subscriptions/<guid>/resourceGroups/<myGroup>/providers/Microsoft.Web/sites/<myFunctionsApp>/functions/<myFunction>",
"maxEventsPerBatch": 1,
"preferredBatchSizeInKilobytes": 64
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Storage.BlobCreated"
],
"advancedFilters": [
{
"operatorType": "StringContains",
"key": "Subject",
"values": [
"-original"
]
}
]
},
"labels": [],
"eventDeliverySchema": "EventGridSchema"
}
}
完整模板:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"resources": [
{
"name": "test123",
"type": "Microsoft.EventGrid/eventSubscriptions",
"apiVersion": "2020-01-01-preview",
"location": "westeurope",
"properties": {
"topic": "/subscriptions/<guid>/resourceGroups/<myGroup>/providers/Microsoft.Storage/storageAccounts/<myStorageAccount>",
"destination": {
"endpointType": "AzureFunction",
"properties": {
"resourceId": "/subscriptions/<guid>/resourceGroups/<myGroup>/providers/Microsoft.Web/sites/<myFunctionsApp>/functions/<myFunction>",
"maxEventsPerBatch": 1,
"preferredBatchSizeInKilobytes": 64
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Storage.BlobCreated"
],
"advancedFilters": [
{
"operatorType": "StringContains",
"key": "Subject",
"values": [
"-original"
]
}
]
},
"labels": [
],
"eventDeliverySchema": "EventGridSchema"
}
}
]
}
错误:
指定的主题属性与事件订阅范围中的预期主题不匹配
答案 0 :(得分:3)
我一直试图通过Azure工具链(ARM模板/ CLI / REST)中的任何选项来做完全相同的事情。我查看了Portal的调用,发现它正在使用您显示的2020-01-01-preview EventGrid API。
经过一些测试,我可以确认新的API允许部署具有AzureFunction的EndpointType的订阅,如下所示:
{
"name": "[concat(variables('eventDomainName'), '/Microsoft.EventGrid/', variables('subscriptionName'))]",
"type": "Microsoft.EventGrid/domains/providers/eventSubscriptions",
"location": "[variables('location')]",
"apiVersion": "2020-01-01-preview",
"properties": {
"destination": {
"endpointType": "AzureFunction",
"properties": {
"resourceId": "[resourceId('Microsoft.Web/sites/functions/', parameters('functionAppName'), parameters('functionName'))]"
}
},
"filter": "[parameters('subscriptionProperties').filter]"
}
}
似乎您的问题与尝试定位AzureFunction无关,并且您使用的是正确的API版本,因此事实并非如此。
我认为问题在于您的“类型”值。我认为应该采用以下格式:// providers / eventSubscriptions
所以应该是Microsoft.Storage/storageAccounts/providers/eventSubscriptions。
答案 1 :(得分:1)
我不认为endpointType
中有单独的AzureFunction
和documented。这只是Webhook处理程序的特例。
此GitHub Repo包含一个示例ARM模板,您可以参考。这是您需要的确切代码段
...
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "[concat(variables('functionUrl'), listKeys(resourceId('Microsoft.Web/sites/host/', variables('functionAppName'), 'default'),'2016-08-01').systemkeys.eventgrid_extension)]"
}
}
...