问题
What I'm doing wrong or how to make it work? I'm using Azure Runtime v1 (need to use .NET Framework, not core).
Function code in Visual Studio as follows:
// This is the default URL for triggering event grid function in the local environment.
// http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName={functionname}
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventGridTrigger]Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.Data.ToString());
}
}
}
When I try to add subscription for that function, regardless if through portal or cli, I'm getting following error:
PS Azure:\> az eventgrid event-subscription create -g [<myGroupName>] --topic-name data-generated --name Func1Subs --endpoint "https://[<myFunctionAppName>].azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName=Function1&code=[<code>]"
Argument 'resource_group_name' has been deprecated and will be removed in version '2.1.0'. Use '--source-resource-id' instead.
Argument 'topic_name' has been deprecated and will be removed in version '2.1.0'. Use '--source-resource-id' instead.
The attempt to validate the provided endpoint https://[<myFunctionAppName>].azurewebsites.net/admin/extensions/EventGridExtensionConfig failed. For more details, visit https://aka.ms/esvalidation.
I tried both system code obtained from GET request on https://[<myFunctionAppName>].azurewebsites.net/admin/host/systemkeys/eventgridextensionconfig_extension?code=[<master_key>]
, default key and even master key itself - same result.
When using the button on the portal to "Add Event Grid subscription" - I also get this error in Notification box.
When I create a function on portal - creating subscription works fine.
Also when I deploy a .netcore function to 2.x runtime - and use the portal button to create subscription - this works fine as well. But like I said - I want to use runtime 1.x to deploy a .NETFramework function.
回答1:
I reproduced this one and some observations here
it works fine if I use default function signature
namespace FunctionApp7
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.ToString(Formatting.Indented));
}
}
}
but when I use signature like you have mentioned, I get error in creating event subscription. I also need to add nuget package for following to compile Microsoft.Azure.EventGrid 3.0.0
namespace FunctionApp10
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventGridTrigger]Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.Data.ToString());
}
}
}
Take a look at following link
https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid
Following signature is not applicable for V1 functions
public static void Run([EventGridTrigger]Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log)
回答2:
You can validate your EventGridTrigger function for Azure Event Grid subscriber using a Postman, see the following:
Request Url:
POST https://{myFuncApp}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={myEventGridTriggerFnc}&code={_masterKey}
Header:
aeg-event-type: SubscriptionValidation
Body:
[{
"id": "123",
"subject": "abc",
"eventType": "xxx",
"eventTime": "2019-01-31T16:17:37.1080645Z",
"data": {
"validationCode": "xxxxxxxx",
"validationUrl": "",
},
"dataVersion": "0",
"metadataVersion": "1",
"topic": "xxxx"
}]
The successful response will return:
{"validationResponse":"xxxxxxxx"}
Notes:
- The Request Url can be copied from the portal yourFunction/Integrate, property Event Grid Subscription URL
- In the case of manually creating a Request Url, use the _master key from the portal yourFunction/Manage page.
- For testing a function body, use the header 'aeg-event-type: Notification'
来源:https://stackoverflow.com/questions/54462432/azure-functions-runtime-v1-eventgrid-subscription-create-fails