有错误时如何跳过Azure函数输出绑定?
我们正在使用简单的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iasynccollector
输出绑定。IAsyncCollector
output binding.