The attempt to validate the provided endpoint failed while creating EvenGridSubscription for Azure Function

Viewed 780

I'm trying to create EventGridSubscription for Azure Function that uses EventGridTrigger. When running New-AzureRmEventGridSubscription cmdlet i see the following error:

Url validation: The attempt to validate the provided endpoint https://blablafunction.azurewebsites.net/admin/EventGridExtensionConfig failed.

Here is azure function code:

[FunctionName("BlobCreatedHandler")]
public static async Task Run([EventGridTrigger]JObject blobEvent,
    [Queue("blob-created-queue", Connection = Strings.StorageAccountConnection)] CloudQueue blobCreatedQueue,
    [Inject(typeof(IBlobCreatedHandler))] IBlobCreatedHandler blobCreatedHandler)
{
    await blobCreatedHandler.Handle(blobEvent, blobCreatedQueue);
}

I tried different versions of AzureRM.EventGrid module. Interesting thing that on versions lower than 0.3.0 it works fine. But all recent versions starting from 0.3.1 are failing with this error. Does someone experience the same?

UPD: Fiddler says that both versions of SDK (good one and bad one) send absolutly identical requests:

{
"properties": {
    "destination": {
        "endpointType": "WebHook",
        "properties": {
            "endpointUrl": "https://blobmalwarescanapptest.azurewebsites.net/admin/EventGridExtensionConfig?functionName=TestFunc&code=PhWghMXtSma188UQccaoErA4Eiw7ygudguHkpq1V0XKMfzA59yBR5g=="
        }
    },
    "filter": {
        "includedEventTypes": [
            "All"
        ],
        "isSubjectCaseSensitive": false
    }
}

and get absolutely the same responses. But on newer versions of SDK seems like Azure EventGrid managing endpoint truncates everything that goes after '?' sign and tries to validate base url (without query parameters).

1 Answers

I've just used the ARM template to achieve the same result. The endpoint that worked for me was: https://<FunctionAppName>.azurewebsites.net/runtime/webhooks/EventGrid?functionName=<functionName>&code=<code>

Though this is also for v2 of azure functions, and I see you're using v1 (because of the JObject as eventgrid trigger).

Edit: Example of my ARM template:

{
  "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
  "name": "[concat(variables('MobileStorageName'), '/Microsoft.EventGrid/', variables('EventSubscriberName'))]",
  "apiVersion": "2018-01-01",
  "dependsOn": [
    "[variables('MobileStorageName')]"
  ],
  "tags": {
    "displayName": "Storage Account Event Subscription"
  },
  "properties": {
    "destination": {
      "endpointType": "WebHook",
      "properties": {
        "endpointUrl": "[variables('FunctionAppEndpoint')]"
      }
    },
    "filter": {
      "subjectBeginsWith": "",
      "subjectEndsWith": "",
      "isSubjectCaseSensitive": false,
      "includedEventTypes": [ "Microsoft.Storage.BlobCreated" ]
    }
  }
}

Note that in my case, I needed StorageV2 (and it's 2018-02-1 api), otherwise it didn't work.

Related