有错误时如何跳过Azure函数输出绑定?

发布于 2025-01-24 05:03:29 字数 505 浏览 3 评论 0原文

我们正在使用简单的Python Azure函数将JSON有效载荷转发到事件中心。我们已经将事件中心配置为功能输出绑定。我们的要求是验证作为标头的一部分出现的apikey,如果请求标头没有apikey或与我们的apikey匹配,我们希望跳过功能输出触发器。我们如何实现这一目标? 当前的代码看起来像这样

import logging
import azure.functions as func
import json
def main(req: func.HttpRequest) -> str:
    logging.info('Send an output)
    try:
        if req.headers.get("MYAPIKEY") == APIKEY: 
            body = req.get_json()
            return json.dumps(body)
    except :
        func.HttpResponse("Function failed")

We are using a simple python azure function to forward a JSON payload to an event hub. We have configured the event hub as the function output binding. Our requirement is to verify an APIKEY that comes as part of the header and if the request header doesn't have the APIKEY or match with our APIKEY, we want to skip the function output trigger. How do we achieve this?
The current code looks like this

import logging
import azure.functions as func
import json
def main(req: func.HttpRequest) -> str:
    logging.info('Send an output)
    try:
        if req.headers.get("MYAPIKEY") == APIKEY: 
            body = req.get_json()
            return json.dumps(body)
    except :
        func.HttpResponse("Function failed")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提赋 2025-01-31 05:03:29
  • 事件中心输出绑定需要每个功能调用至少一个输出。
  • 如果您使用的是返回值版本,而不是尝试使用iasynccollector输出绑定。
  • 您可以检查此 github 讨论您可以在其中使用函数方法。
  • 这是另一个 gitbhub 与相关问题的讨论。
  • Event hub output binding requires at least one output per function call.
  • If you are using return value version rather than that try using IAsyncCollector output binding.
  • You can check this Github discussion where you can use function out method.
  • Here is the other Gitbhub discussion with related issue.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文