根据您的描述,必须使用以下属性:
[FunctionName("EventGridTrigger")]
您可以使用 Postman 对其进行测试:
http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName=EventGridTrigger
请注意,必须添加以下标题:
Aeg-Event-Type:Notification
更新:
以下是我通过 ngrok 和 VS 2017 版本 15.7.5 创建的自定义主题的工作功能:
// This is the default URL for triggering event grid function in the local environment.
// http://localhost:7071/admin/extensions/EventGridExtensionConfig?functionName={functionname}
// Aeg-Event-Type:Notification
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FunctionApp10
{
public static class Function2
{
[FunctionName("Function2")]
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
{
log.Info(eventGridEvent.ToString(Formatting.Indented));
}
}
}
和依赖项:

更新2:
VS 从 EventGridTrigger 模板生成的版本 2 的函数如下:
// Default URL for triggering event grid function in the local environment.
// http://localhost:7071/runtime/webhooks/EventGridExtensionConfig?functionName={functionname}
// Aeg-Event-Type:Notification
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Extensions.Logging;
namespace FunctionApp11
{
public static class Function2
{
[FunctionName("Function2")]
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
{
log.LogInformation(eventGridEvent.Data.ToString());
}
}
}
和依赖项:

localhost:7071 邮递员测试的注意事项:
有效负载必须是事件数组