本地 DOcker 容器中的 Azure Cosmos DB SSL 连接错误

问题描述 投票:0回答:1

我正在 Docker 容器中运行本地 Cosmos DB。我已经关注了这个doc

我正在 Visual Studio Code 中运行 Azure Function。我还使用此方法从 Docker 导入了 Cosmos DB 的 SSL 证书。我运行的是 Windows 11 操作系统。

但是我不断收到此错误:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.MyCoFunc'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create container information for products in database cosmicworks4 with lease leases in database cosmicworks4 : The SSL connection could not be established, see inner exception. System.Net.Http: The SSL connection could not be established, see inner exception. System.Private.CoreLib: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot.
[2023-12-23T16:54:16.993Z] Error indexing method 'Functions.MyCoFunc'
using System;
using System.Collections.Generic;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace Function_CosmosDB_Trigger
{
    public class MyCoFunc
    {
        private readonly ILogger _logger;

        public MyCoFunc(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<MyCoFunc>();
        }

        [Function("MyCoFunc")]
        public void Run([CosmosDBTrigger(
            databaseName: "cosmicworks4",
            containerName: "products",
            Connection = "DBConnectionString",
            LeaseContainerName = "leases",
            CreateLeaseContainerIfNotExists = true)] IReadOnlyList<MyDocument> input)
        {
            if (input != null && input.Count > 0)
            {
                _logger.LogInformation("Documents modified: " + input.Count);
                _logger.LogInformation("First document Id: " + input[0].id);
            }
        }
    }

    public class MyDocument
    {
        public string id { get; set; }

        public string Text { get; set; }

        public int Number { get; set; }

        public bool Boolean { get; set; }
    }
}

出了什么问题?

谢谢

azure azure-functions azure-cosmosdb
1个回答
0
投票

即使最初我也遇到了同样的错误。

enter image description here

我执行了以下步骤来解决此错误 -

  • 导出证书

enter image description here

  • 通过将证书添加到受信任的根证书颁发机构证书存储来安装证书。

enter image description here

enter image description here

  • 完成上述步骤后,当我调试我的函数时,我得到了预期的响应。

enter image description here

  • 甚至你可以在 Visual Studio 中使用它,如下所示 -

enter image description here

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.