Azure Function Timer 触发器和 API 管理 - 手动执行返回 404

标签 azure azure-functions azure-api-management

我有一个函数应用程序:

  • 计时器触发器触发的一些功能
  • 还有一些由 HTTP 触发器触发。

我还为函数应用设置了 Azure API 管理服务,其中HTTP 触发函数定义了其端点。

我正在尝试按照此处的指南手动触发计时器触发功能之一 https://learn.microsoft.com/en-us/azure/azure-functions/functions-manually-run-non-http

尽管 URL 和 x-functions-key 看似正确,但我在 Postman 中得到了 404 结果。

功能: enter image description here

关键:

enter image description here

请求:

enter image description here

我还注意到:

  • 如果我不包含 x-functions-key header ,则会得到 401 Unauthorized 结果
  • 如果我输入不正确 key ,则会收到403 Forbidden

是否与为函数应用设置的 API 管理服务有关?

如何进一步解决此问题?

最佳答案

我已经解决了。

事实证明,Azure Functions 计时器触发器需要六个部分的 cron 表达式(我只知道 the five part style )

没有它,它就无法工作 - 遗憾的是,这在用户界面中不容易被注意到。 通过调查 Application Insights 日志,我意识到:

enter image description here

功能页面显示一切正常:

enter image description here

更改 CRON 格式已修复 404 问题,我开始收到 202 已接受响应。

作为奖励,我必须添加:

即使响应是 202 Accepted,触发也无法正常工作,因为我的函数返回类型是 Task<IActionResult>定时器触发的功能不接受这种方式。

同样,只有 ApplicationInsights 显示有任何问题:

The 'MonkeyUserRandom' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'MonkeyUserRandom'. 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.).

这是“手动触发非 http 函数不起作用”的额外提示。

关于Azure Function Timer 触发器和 API 管理 - 手动执行返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67867949/

相关文章:

.net - Azure API 对于包含内容的 Db 调用返回 204 No Content

azure - 使用 Az CLI/PowerShell 从 Function App 重新导入 API 管理 API

azure - 从 terraform 创建服务主体时出现权限不足,无法完成操作的错误

azure - 如何对现有文件多次运行 blob 存储触发器

azure - API 管理通过服务标签限制 IP 范围

javascript - 响应中 'Access-Control-Allow-Origin' header 的值不能是 azure 函数和 javascript 中的通配符 '*'

azure - 配置为从死信队列接收消息时未获取常规服务总线消息

azure - Microsoft.WindowsAzure.StorageClient.CloudBlockBlob.DownloadBlockList 返回 0 个 block

ASP.NET Core - Web API 中 SPA 路由的缓存问题

C# 将数据保存到数据库并退出程序