3

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 Answers1

0

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.

Lars Celie
  • 622
  • 5
  • 17
  • I tried your endpoint: it might work with ARM template but it doesn't work with latest versions of AzureRM.Eventgrid PS module either (that's possibly because you use older version of API in your template? just a guess). I tried it on older versions: endpoint validation passes but event itself could not be delivered and azure function is not being triggered. – Siarhei Machel Sep 10 '18 at 16:40
  • What API version are you targeting in your ARM template? (i want to compare it with the one that PS cmdlet uses) – Siarhei Machel Sep 10 '18 at 16:48
  • @SiarheiMachel I've added a snippet of the arm template so you can compare. – Lars Celie Sep 11 '18 at 12:10