gpt4 book ai didi

python - 已部署 Azure 函数但从未在 blob 输入上运行

转载 作者:行者123 更新时间:2023-12-03 06:29:30 25 4
gpt4 key购买 nike

我们正在设置一个 Azure 函数,一旦我们在 Azure Blob 存储中拥有文件,就会触发该函数。

此文件将用作 Github 上托管的 python 脚本的输入。

这是使用 Visual Studio 代码设置函数后生成的 azure 函数基本脚本:

导入日志记录

将 azure.functions 导入为 func

def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")

目标是,上传到 blob 中的 TOML 输入文件应充当变量的加载器。

然后运行该脚本并生成另一个文件,该文件将保存在另一个 blob 中。

使用网络应用程序,我们可以加载到 blob 中,但是,该功能不是通过查看监视器选项卡来触发的:

enter image description here

我们想要的是在 azure 函数的 main() 中,触发 github 上的 python 项目以使用输入文件运行。所以它变成:

def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
# python src/main.py fileInput.toml

知道为什么启用的功能没有运行以及要在其功能中添加什么吗?

最佳答案

我已经在我的环境中重现并得到了如下预期结果,并遵循以下过程:

首先,创建一个函数应用和存储帐户。

然后在 Function App 的配置部分检查 AzureWebJobsStorage 中的连接字符串是否正确:

  • 从此处的存储帐户复制连接字符串:

enter image description here

  • 并粘贴到函数应用程序中:

enter image description here

然后创建一个blob函数触发器:

enter image description here

现在在函数触发器代码中:

 import logging

import azure.functions as func


def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")

现在在 function.json 中检查容器名称:

samples-workitems

enter image description here

现在在链接到 Function 应用的存储帐户中创建一个容器:

enter image description here

然后将 blob 上传到容器内:

enter image description here

上传 blob 后:

enter image description here输出:

检查功能应用程序的日志部分:

现在使用以下查询来检查 blob 触发器是否被触发:

traces
|where message contains "Python blob trigger function processed blob"

enter image description here

关于python - 已部署 Azure 函数但从未在 blob 输入上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75335059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com