Deploying Event Grid Using ARM Template

Sairam Ganji 46 Reputation points
2022-11-01T05:05:43.38+00:00

Hi Team,

I am trying to deploy Event Grid using ARM Template. Here, I am fetching or rather got the ARM template from an already created EventGrid( through Export Template). Below is the Template.

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"systemTopics_EventGridSubDemo_name": {
"defaultValue": "EventGridSubDemoTest",
"type": "String"
},
"StorageAccounts_jsoninputfile_externalid": {
"defaultValue": "/subscriptions/{subscription-id}/resourceGroups/{resourcegroup}/providers/Microsoft.Storage/StorageAccounts/{storage-account}",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.EventGrid/systemTopics",
"apiVersion": "2022-06-15",
"name": "[parameters('systemTopics_EventGridSubDemo_name')]",
"location": "eastus",
"properties": {
"source": "[parameters('StorageAccounts_jsoninputfile_externalid')]",
"topicType": "Microsoft.Storage.StorageAccounts"
}
},
{
"type": "Microsoft.EventGrid/systemTopics/eventSubscriptions",
"apiVersion": "2022-06-15",
"name": "[concat(parameters('systemTopics_EventGridSubDemo_name'), '/EventGridDemo')]",
"dependsOn": [
"[resourceId('Microsoft.EventGrid/systemTopics', parameters('systemTopics_EventGridSubDemo_name'))]"
],
"properties": {
"destination": {
"properties": {
"resourceId": "[parameters('StorageAccounts_jsoninputfile_externalid')]",
"queueName": "eventgriddemobus",
"queueMessageTimeToLiveInSeconds": 604800
},
"endpointType": "StorageQueue"
},
"filter": {
"includedEventTypes": [
"Microsoft.Storage.BlobCreated",
"Microsoft.Storage.BlobDeleted"
],
"enableAdvancedFilteringOnArrays": true
},
"labels": [],
"eventDeliverySchema": "EventGridSchema",
"retryPolicy": {
"maxDeliveryAttempts": 30,
"eventTimeToLiveInMinutes": 1440
}
}
},
{
"type": "Microsoft.EventGrid/systemTopics/eventSubscriptions",
"apiVersion": "2022-06-15",
"name": "[concat(parameters('systemTopics_EventGridSubDemo_name'), '/EventGridDemoLogicApp')]",
"dependsOn": [
"[resourceId('Microsoft.EventGrid/systemTopics', parameters('systemTopics_EventGridSubDemo_name'))]"
],
"properties": {
"destination": {
"properties": {
"maxEventsPerBatch": 1,
"preferredBatchSizeInKilobytes": 64
},
"endpointType": "WebHook"
},
"filter": {
"includedEventTypes": [
"Microsoft.Storage.BlobCreated",
"Microsoft.Storage.BlobDeleted"
]
},
"eventDeliverySchema": "EventGridSchema",
"retryPolicy": {
"maxDeliveryAttempts": 30,
"eventTimeToLiveInMinutes": 1440
}
}
}
]
}

But when I try to deploy it, below error is thrown

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"InvalidRequest\",\r\n \"message\": \"Invalid event subscription request: Supplied URL is invalid. It cannot be null or empty and should be a proper HTTPS URL like https://www.example.com.\"\r\n }\r\n}"}]}}

What I see is , the subscription for storage account is getting created, so guessing its an issue in logic App subscription

Thanks in Advance

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,840 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
313 questions
0 comments No comments
{count} vote

Accepted answer
  1. MayankBargali-MSFT 68,471 Reputation points
    2022-11-02T07:06:14.683+00:00

    @Sairam Ganji Thanks for reaching out. As per the ARM template name [concat(parameters('systemTopics_EventGridSubDemo_name'), '/EventGridDemoLogicApp')] I can see that you have define the endpointType as WebHook but I don't see endpoint property with the endpoint URL as documented here. Therefore, the error is expected.

    You should always specify the endpoint URL while defining the type as WebHook. As you are using the logic app event grid trigger so need to leverage listCallbackUrl to get the URL details.

     "endpointType": "WebHook",  
    					 "properties": {  
                         "endpointUrl": "[listCallbackUrl(concat(resourceId('Microsoft.Logic/workflows', parameters('workflowname')),'/triggers/',parameters('logic_app_trigger_name')), '2017-07-01').value]"  
                       }  
    

    parameters('workflowname') will be your logic app name and parameters('logic_app_trigger_name') will be your logic app trigger name. Make sure to validate the right trigger name from your logic app workflow that you may have defined.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Alistair Ross 7,101 Reputation points Microsoft Employee
    2022-11-01T10:23:37.813+00:00

    Hello @Sairam Ganji

    I am not an Event Grid expert, but looking at the documentation the webhook is created when you deploy the logic app.

    Use Logic Apps to implement business processes to process Event Grid events. You don't create a webhook explicitly in this scenario. The webhook is created for you automatically when you configure the logic app to handle events from Event Grid

    {  
      "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",  
      "name": "[concat(parameters('TopicName'), '/Microsoft.EventGrid/', variables('name'))]",  
      "location": "[parameters('Location')]",  
      "apiVersion": "2018-01-01",  
      "properties": {  
        "destination": {  
          "endpointType": "WebHook",  
          "properties": {  
            "endpointUrl": "[parameters('Endpoint')]"  
          }  
        },  
        "filter": {  
          "includedEventTypes": [  
            "[parameters('EventType')]"  
          ]  
        }  
      },  
      "dependsOn": [  
      ]  
    }  
    

    I hope this helps provide you with the information you need. If it does, please make sure to mark the question as answered so it helps other people in future.

    Kind Regards

    Alistair

    https://learn.microsoft.com/en-us/azure/event-grid/handler-webhooks#rest-example-for-put