使用 Python 的 Azure 函数 - Blob 触发器未触发

Azure Function using Python - Blob trigger not firing

我正在使用 Python 中编写的 Azure 函数之一,它应该根据 Blob 触发事件被调用。但是,当我在 azure 函数应该监视的 blob 容器中上传 zip 文件时,触发器没有触发。

以下是 local.settings.json 文件 -

{
  "IsEncrypted": false,
  "Values": 
    {
    "AzureWebJobsStorage": "blob (connection string) that was created when Azure function is created",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "My_STORAGE": "blob (connection string) that function should monitor"
    }
} 

以下是 function.json 文件 -

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "mycontainer/{name}",
      "connection": "My_STORAGE"
    }
  ]
}

以下是我的代码 init.py -(test_func 是用户定义的函数来执行一些业务逻辑)

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

当我在“mycontainer”容器中上传 zip 文件时,azure 函数没有触发。

StorageV2(通用 v2) 帐户类型的“mycontainer”。我正在使用 Python 3.8 版本。

这个“mycontainer”已经自动创建了一个名为 $logs 的容器,它有一个 day wise 文件夹,其中有一个日志文件,其中提到了我在“mycontainer”中上传的文件,但是,没有任何 blob 触发事件的迹象在 Azure 函数上。

"My_STORAGE" 添加为 Azure Functions 配置设置中的应用程序设置。我在 Azure Functions 部署后上传 Local Settings

知道出了什么问题吗?

谢谢。

问题是由连接字符串错误引起的。连接字符串中的 AccountName 应该是存储帐户名称而不是容器名称。

所以只要把AccountName=mycontainer改成AccountName=<storage account name>就可以了。

顺便说一句:

连接字符串应该是:DefaultEndpointsProtocol=https;AccountName=<storage account name>;AccountKey=xxxxxxxxxx==;EndpointSuffix=core.windows.net

“function.json”中的“路径”应该是:"path": "<container name>/{name}"

我遇到过类似的问题。通过将连接字符串作为键值对添加到功能 App-> 配置-> 设置中的应用程序设置中解决了。我假设如果 Azure Functions 应用程序部署在不同的存储容器中,则必须这样做,为此需要不同的连接字符串。

local.settings.json 文件中的 _STORAGE 键复制到新的应用程序设置 key-value: