0

I have an Azure Function executed by Event Grid trigger. The function is debugged and functioning as designed. I was able to successfully create a subscription to an Event Grid topic using UI in the Azure Portal (click Add Event Grid subscription and complete the on-screen form).

The problem is I cannot get the endpoint format correct when attempting to use the CLI (Cloud Shell logged in as Administrator) to create a subscription. The basic template I'm using is

az eventgrid event-subscription create --resource-group $resourceGroup
--topic-name $topicName
--included-event-types $includedEventTypes
--name $eventSubscriptionName
--endpoint  https://XXX.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName=FunctionName&code=ABC123

I've tried copying the auto-populated endpoint, including its code parameter, from the UI. It works in the UI but not from CLI. When I run the above script using the endpoint and code provided in the portal, I get the following

The term 'code=<XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX> is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If I omit the code, I get a message indicating the subscription failed because it couldn't validate the endpoint.

If I attempt to use the endpoint, in the form usually seen for function endpoints, https://XXX.azurewebsites.net/FunctionName, I also get complaints about validation.

What is the proper format for the endpoint when creating a subscription from the CLI in Cloud Shell? Do I include the code parameter or not? Where do I get the proper code?

Using:

Microsoft.NET.Sdk.Functions 1.0.19
Microsoft.Azure.EventGrid 1.4.0
Microsoft.Azure.WebJobs.Extensions.EventGrid 1.0.0
DenaliHardtail
  • 27,362
  • 56
  • 154
  • 233
  • have a look at https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid – Roman Kiss Sep 01 '18 at 16:28
  • the full subscriberUrl for EventGridTrigger has the following format: https://{FunctionAppName}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={EventGridTriggerFunctionName}&code={masterKey} – Roman Kiss Sep 01 '18 at 16:30
  • I tried subscribing using the _master and default Host Keys and the system key created by sending a GET request with the _master key. All resulted in the `The term 'code=XXXX' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.` – DenaliHardtail Sep 01 '18 at 17:02
  • I have just tested it with a _master key using CLI on the portal (update event subscription) with an endpoint value wrapped by double quotes like recommended by Jerry's answer. – Roman Kiss Sep 01 '18 at 17:57
  • I just tried double quotes and using the _master key. Now getting `The attempt to validate the provided endpoint https://XXX.azurewebsites.net/admin/extensions/EventGridExtensionConfig failed. For more details, visit https://aka.ms/esvalidation.` – DenaliHardtail Sep 01 '18 at 18:07
  • Note, that the function name is case sensitive. Try to match exactly to the your function name. – Roman Kiss Sep 01 '18 at 18:17

1 Answers1

0

Try to wrap your function endpoint with quote sign, & seems a reserved sign in CLi syntax hence your parameter code is cut from the url.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
  • Wrapping the endpoint in quotes solved the problem. At some point, the function app stopped working. After publishing again and placing the endpoint in quotes and using the _master key, everything worked as expected. – DenaliHardtail Sep 01 '18 at 19:44