Azure Functions:对 Blob 存储秘密存储库执行读取操作时出错

Azure Functions: There was an error performing a read operation on the Blob Storage Secret Repository

在本地测试 Azure Functions 时,我收到此错误。

“对 Blob 存储秘密存储库执行读取操作时出错。请确保 'AzureWebJobsStorage' 连接字符串有效。”

我有 Azure Blob 存储设置,包括存储模拟器和存储资源管理器。如何解决?

我在使用 Azure Durable Functions 时遇到了这个问题,我在这里找到了解决方法:https://github.com/Azure/azure-functions-host/issues/3795#issuecomment-430337085

local.settings.json 中,添加一个名为 AzureWebJobsSecretStorageType 的新设置并将其设置为“文件”。

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "AzureWebJobsSecretStorageType": "files"
  }
}

@mattsmith5 的回答不正确。请不要将“AzureWebJobsStorage”参数更改为您的实时存储帐户,因为可能会产生额外费用,并且您可能会对在线环境产生无法预料的副作用或影响。 存储模拟器早已弃用,您应该使用 azurite 来模拟本地存储。例如,您可以使用 npm (npm install -g azurite) 或许多其他 ways.

下载蓝铜矿

“UseDevelopmentStorage=true”是在本地环境中使用的正确设置,尤其是当您要使用持久函数或其他计算或 I/O 繁重任务时。 关于您的问题,azurite 在您为其虚拟存储后端执行它的文件夹中创建了多个 json 文件。如果你 运行 azurite 没有任何参数,应该存在以下文件:

  • __azurite_db_blob_extent__.json
  • __azurite_db_queue__.json
  • __azurite_db_queue_extent__.json
  • __azurite_db_table__.json

此外,通常有两个或更多文件夹的名称与此类似:

  • __blobstorage__
  • __queuestorage__

要强制 azure-functions-core-tools 运行重置存储声明和句柄的时间,首先停止 azurite 和所有 func 实例,删除上述文件和文件夹并重新启动(首先是蓝铜矿)。

当然所有内容都会消失,但本地开发存储永远不应该用于持久数据。

我的两分钱。

我正在尝试 运行 在我的本地计算机上实现持久功能。

我遇到了这个错误。

There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid

我看了this answer from the github issue

我完全删除了我的文件夹,路径如下

C:\Users\YourUserName\AppData\Local\Temp\Azurite 

现在运行一切都好起来了。

文件夹看起来像这样。

对于在设置 "AzureWebJobsSecretStorageType": "Files" 后继续出现 blob 读取错误的任何其他人,将 Microsoft.Azure.WebJobs.Extensions.Storage 包从 v5 降级到 v4 可以修复它。 (我用的是v4.0.5)。

这可能特定于 .NET 项目。如果您不熟悉修改 c# 依赖项,请在 .csproj 文件中找到 PackageReference 对象并更改版本。然后你可以 运行 dotnet restore 到 update/refresh.

对于那些不喜欢阅读文字的人:

project-name.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
      ...
  </PropertyGroup>
  <ItemGroup>
    ...
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5"/>
    ...
  </ItemGroup>
  ...
</Project>

为了 SEO,这是我的错误:

System.InvalidOperationException: Secret initialization from Blob storage failed due to missing both an Azure Storage connection string and a SAS connection uri. For Blob Storage, please provide at least one of these. If you intend to use files for secrets, add an App Setting key 'AzureWebJobsSecretStorageType' with value 'Files'.

None 的其他答案对我有用,所以我将在这里分享我的解决方案。我试过了:

  • 改变AzureWebJobsSecretStorageType
  • 终止蓝铜进程并重新启动它
  • 正在从 AppData 中删除所有文件

None 有效。我的解决方法是使用 npm install -g azurite 安装 azurite,然后使用 azurite 安装 运行。之后我的旧项目又开始工作了。