[英]Read data from Azure blob storage in Azure Function in python
Please how do I read in data from my Azure Storage account when I launch my Function app.请问我如何在启动我的函数应用程序时从我的 Azure 存储帐户中读取数据。 I need to read the saved weights for my machine learning model at runtime.
我需要在运行时读取为我的机器学习模型保存的权重。 I want to read the model directly from the storage account because the model is expected to be updated daily and do not want have to manually redeploy the model.
我想直接从存储帐户中读取模型,因为该模型预计每天都会更新,并且不想手动重新部署模型。
Thanks谢谢
For this requirement, you can go to your storage blob first and click " Generate SAS " to generate " Blob SAS URL " (you can also define the start date and expiry date of the url).对于这个需求,你可以先到你的storage blob,点击“ Generate SAS ”,生成“ Blob SAS URL ”(你也可以定义url的开始日期和到期日期)。
Then go to your python function, install azure-storage-blob
module by running pip install azure-storage-blob
command in VS code.然后转到您的 python 函数,通过在 VS 代码中运行
pip install azure-storage-blob
命令来安装azure-storage-blob
模块。 After that, write the function code like:之后,编写函数代码如下:
Start the function and trigger it, we can see the content of test1.txt
printed out by logging.info
.启动函数并触发,我们可以看到
logging.info
打印出来的test1.txt
的内容。
Below is all of my function code for your reference:以下是我所有的功能代码供您参考:
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
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.