请在启动Function应用程序时如何从Azure存储帐户读取数据。我需要在运行时为我的机器学习模型读取保存的权重。我想直接从存储帐户中读取模型,因为该模型预计每天都会更新,并且不需要手动重新部署该模型。
谢谢
为此,您可以先转到存储Blob,然后单击“ Generate SAS ”以生成“ Blob SAS URL ”(也可以定义URL的开始日期和有效日期)。
然后转到python函数,azure-storage-blob
通过pip install azure-storage-blob
在VS代码中运行命令来安装模块。之后,编写如下功能代码:
启动功能并触发它,我们可以看到test1.txt
打印出来的内容logging.info
。
以下是我所有的功能代码,供您参考:
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
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句