【发布时间】:2021-02-22 19:30:07
【问题描述】:
当我启动我的函数应用程序时,如何从我的 Azure 存储帐户中读取数据。我需要在运行时为我的机器学习模型读取保存的权重。 我想直接从存储帐户中读取模型,因为模型预计每天都会更新,并且不想手动重新部署模型。
谢谢
【问题讨论】:
标签: azure-devops azure-functions azure-data-lake azure-blob-storage azure-function-app
当我启动我的函数应用程序时,如何从我的 Azure 存储帐户中读取数据。我需要在运行时为我的机器学习模型读取保存的权重。 我想直接从存储帐户中读取模型,因为模型预计每天都会更新,并且不想手动重新部署模型。
谢谢
【问题讨论】:
标签: azure-devops azure-functions azure-data-lake azure-blob-storage azure-function-app
对于这个需求,你可以先进入你的存储blob,点击“Generate SAS”生成“Blob SAS URL”(也可以定义开始日期和网址的到期日期)。
然后转到您的 python 函数,通过在 VS 代码中运行 pip install azure-storage-blob 命令来安装 azure-storage-blob 模块。之后,编写如下函数代码:
启动函数并触发它,我们可以看到logging.info打印出来的test1.txt的内容。
下面是我的全部功能代码供大家参考:
import logging
import azure.functions as func
from azure.storage.blob import BlobClient
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
blob_client = BlobClient.from_blob_url("copy your Blob SAS URL here")
download_stream = blob_client.download_blob()
logging.info('=========below is content of test1')
logging.info(download_stream.readall())
logging.info('=========above is content of test1')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
【讨论】: