简体   繁体   English

在 python 中从 Azure Function 中的 Azure blob 存储读取数据

[英]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.

相关问题 使用 python notebook 从 Azure Blob 读取数据到内存中 - Read data from Azure Blob to In-memory using python notebook 白名单 Azure Azure 存储中的自动化帐户以从 blob 读取压缩模块并上传到 azure 自动化模块 - Whitelist Azure Automation account in Azure Storage to read zipped module from blob and upload in azure automation module 我们如何使用 Python 将文件加载到 Azure Blob 存储或 Azure 数据湖存储? - How can we use Python to load files into Azure Blob Storage or Azure Data Lake Storage? Azure Function in PowerShell to copy file from Azure Blob storage to Azure VM - Azure Function in PowerShell to copy file from Azure Blob storage to Azure VM 将文件数据从 Azure blob 存储访问到变量 - Accessing data of a file from Azure blob storage to a variable Azure 异常 - Blob 存储 - Azure Exception - Blob Storage 将文件从 azure blob 存储复制到管道中的本地存储 - Copy files from azure blob storage to local storage in pipeline Json to excel from devops to storage account with help of azure function in python - Json to excel from devops to storage account with help of azure function in python Azure 媒体服务从私有 blob 存储容器提交 JobInputHttp - Azure Media Service Submit JobInputHttp from a private blob storage container 将 CSV 从 Azure Automation 导出到 Microsoft Teams 而不是 blob 存储? - Export a CSV from Azure Automation to Microsoft Teams instead of blob storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM