Docker 托管的 Azure 函数无法 link 事件网格

Docker hosted Azure Function fails to link with Event Grid

我正在尝试通过事件网格将托管在 azure blob 存储上的静态站点连接到 azure 函数(托管在 docker 容器中)。我的计划是优化添加到 blob 存储的图像以减小文件大小的功能。

我很欣赏它有点人为的示例,但我希望了解事件网格和 docker,这对我很有用。

目前我无法将事件网格连接到我的 azure 函数。从函数向事件网格添加订阅在门户中不可用,因为它在 docker 容器中。

我正在按照主密钥 getting the function system key 上微软指南中的这些步骤进行操作。 (稍后用于设置订阅)

当我点击 link 时: http://<func-app>.azurewebsites.net/admin/host/systemkeys/eventgrid_extension?code=<master_key> 我收到 404(使用 HTTPS 时相同)。

我替换了函数应用程序名称并从这里获取了 master_key(名为 _master):

我只能假设我做错了什么,但我不知道是什么,感谢您的帮助!

为 linux 函数生成系统密钥似乎有些问题。我确实遇到了同样的错误,而在 Windows 上一切正常。

解决方法是直接使用主密钥配置端点,这对我来说非常有效。

https://{functionappname}.azurewebsites.net/runtime/webhooks/eventgrid?functionName={functionname}&code={masterkey}

终于搞清楚了,修复它需要 2 个步骤:

  • 确保您使用的是正确的方法签名。我已将 IActionResult 作为 return 类型添加到我的函数中,而不是此方法签名:public static void EventGridTest([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)(使用 async Task 而不是 void 也是可以接受的)。由于签名不正确,函数运行时无法找到有效的函数签名,直到我实际上 运行 func host start 才出现此错误,此时我得到以下信息:
Microsoft.Azure.WebJobs.Host: Error indexing method '<funcName>'.
Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type IActionResult&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
  • 其次,文档中描述的获取系统密钥的端点不存在(Returns 404)。正如 Jerry Liu 所述 使用“_master”密钥代替系统密钥。

非常感谢 Roman Kiss & Jerry Lui 帮助我解决了这个问题。

我也遇到过同样的问题。在 Docker 容器中部署带有 EventGridTriggers 的 FunctionApp 时,eventgrid_extension 键有时不会显示。有时它会立即出现,有时会在几个小时后出现,有时永远不会出现。

我注意到即使 eventgrid_extension 密钥未显示在 Azure 门户中,它在与 FunctionApp 关联的存储 Blob 中可用。

也许直接从 blob 中提取密钥可以用作解决方法。