Как добавить AzureFunction в качестве конечной точки подписки на события в шаблоне ARM?

Я написал шаблон ARM для создания подписки на события в существующей учетной записи хранения, где мне нужно прослушивать события blob.created и blob.deleted конкретного контейнера больших двоичных объектов и отправлять их в приложение функции триггера событийной сети Azure.

Приложение functionapp уже развернуто в Azure https://myfunctionapp.azurewebsites.net, и мне трудно пытаюсь создать подписку на событие через шаблон ARM. Обратите внимание, что я использовал версию API 2020-01-01-preview, чтобы использовать AzureFunction в качестве конечной точки. Шаблон выглядит следующим образом:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "appName": {
        "type": "string",
        "metadata": {
            "description": "Name of the function app"
        }
    },
    "functionName": {
        "type": "string",
        "defaultValue": "MyFunction",
        "metadata": {
            "description": "Name of the function"
        }
    },
    "eventSubName": {
        "type": "string",
        "defaultValue": "myfunctionappsub",
        "metadata": {
            "description": "The name of the event subscription to create."
        }
    },
    "storageName": {
        "type": "string",
        "metadata": {
            "description": "Storage account name"
        }
    },
    "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
            "description": "Storage account location"
        }
    },
    "containerNamefilter": {
        "type": "string",
        "defaultValue": "-inputblob",
        "metadata": {
            "description": "Container name filter"
        }
    }
},
"variables": {
    "functionAppName": "[resourceId('Microsoft.Web/sites/functions/', parameters('appName'), parameters('functionName'))]"
},
"resources": [
    {
        "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
        "name": "[concat(parameters('storageName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
        "apiVersion": "2020-01-01-preview",
        "dependsOn": [
            "[parameters('storageName')]"
        ],
        "properties": {
            "destination": {
                "endpointType": "AzureFunction",
                "properties": {
                    "resourceId": "[variables('functionAppName')]"
                }
            },
            "filter": {
                "subjectBeginsWith": "",
                "subjectEndsWith": "",
                "isSubjectCaseSensitive": false,
                "includedEventTypes": [
                    "Microsoft.Storage.BlobCreated",
                    "Microsoft.Storage.BlobDeleted"
                ],
                "advancedFilters": [
                    {
                        "key": "subject",
                        "operatorType": "StringContains",
                        "value": "[parameters('containerfilter')]"
                    }
                ]
            }
        }
    }
]
}

Это ошибка, которую я получаю, когда пытаюсь запустить его в конвейере:

2020-04-15T11:09:11.5347864Z Starting template validation.
2020-04-15T11:09:11.5368215Z Deployment name is azuredeploy-xxxxxxx-xxxxxx-xxxx
2020-04-15T11:09:13.1700166Z Template deployment validation was completed successfully.
2020-04-15T11:09:13.1700897Z Starting Deployment.
2020-04-15T11:09:13.1703528Z Deployment name is azuredeploy-xxxxxxx-xxxxxx-xxxx
2020-04-15T11:10:02.5842880Z There were errors in your deployment. Error code: DeploymentFailed.
2020-04-15T11:10:02.5893091Z ##[error]At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.
2020-04-15T11:10:02.5910677Z ##[error]Details:
2020-04-15T11:10:02.5915877Z ##[error]Conflict: {
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'.",
    "details": [
      {
        "code": "Internal error",
        "message": "The operation failed due to an internal server error. The initial state of the impacted resources (if any) are restored. Please try again in few minutes. If error still persists, report 72c636d4-6d09-4c50-8886-7153ddf2a4ee:4/15/2020 11:09:50 AM (UTC) to our forums for assistance or raise a support ticket ."
      }
    ]
  }
}
2020-04-15T11:10:02.5918976Z ##[error]Task failed while creating or updating the template deployment.
2020-04-15T11:10:02.5953000Z ##[section]Finishing: Create or update eventsubscription in RG

Я здесь что-то не так делаю? Я новичок в шаблонах ARM.


person noobmaster007    schedule 15.04.2020    source источник
comment
Пожалуйста, проверьте этот вопрос, он похож на ваш stackoverflow.com/questions/60207556/   -  person Jagrati Modi    schedule 16.04.2020


Ответы (1)


Если вы хотите создать подписку сетки событий для существующей учетной записи хранения, обратитесь к следующему шаблону

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {

    "functionGroup": {
        "type": "string",
        "defaultValue" : "jimtest",
        "metadata": {
            "description": "he group name of  function app"
        }
    },
    "appName": {
        "type": "string",
        "defaultValue" : "testfunjs",
        "metadata": {
            "description": "Name of the function app"
        }
    },
    "functionName": {
        "type": "string",
        "defaultValue": "EventGridTrigger1",
        "metadata": {
            "description": "Name of the function"
        }
    },
    "eventSubName": {
        "type": "string",
        "defaultValue": "myfunctionappsub",
        "metadata": {
            "description": "The name of the event subscription to create."
        }
    },
    "storageName": {
        "type": "string",
        "defaultValue" : "andyprivate",
        "metadata": {
            "description": "Storage account name"
        }
    },
    "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
            "description": "Storage account location"
        }
    },
    "containerNamefilter": {
        "type": "string",
        "defaultValue": "test",
        "metadata": {
            "description": "Container name filter"
        }
    }
},
"variables": {
    "functionId" :"[resourceId(parameters('functionGroup'),'Microsoft.Web/sites/functions/', parameters('appName'), parameters('functionName'))]",  
},
"resources": [
{
        "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
        "name": "[concat(parameters('storageName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
        "apiVersion": "2020-01-01-preview",
        "properties": {
            "destination": {
                "endpointType": "AzureFunction",
                "properties": {
                    "resourceId": "[variables('functionId')]"
                }
            },
            "filter": {
                "subjectBeginsWith": "",
                "subjectEndsWith": "",
                "isSubjectCaseSensitive": false,
                "includedEventTypes": [
                    "Microsoft.Storage.BlobCreated",
                    "Microsoft.Storage.BlobDeleted"
                ],
                "advancedFilters": [
                    {
                        "key": "subject",
                        "operatorType": "StringContains",
                        "value": "[parameters('containerNamefilter')]"
                    }
                ]
            }
        }
    }

]
}

введите здесь описание изображения  введите описание изображения здесь

person Jim Xu    schedule 16.04.2020
comment
Большое спасибо @JimXu, это сработало! Но я заметил, что фильтр, который я добавляю, не настраивается. Он показывает ключ и оператор, но значение не устанавливается. Есть ли что-нибудь еще, что я должен добавить в шаблон, чтобы получить фильтры? - person noobmaster007; 16.04.2020
comment
Исправлено добавлением массива values вместо одного value. Спасибо! Добавьте сюда ссылку на лазурную документацию для всех, кому она нужна. ссылка - person noobmaster007; 17.04.2020