C# 如何从Lambda函数连接到AWS DocumentDB?

C# 如何从Lambda函数连接到AWS DocumentDB?,c#,amazon-web-services,aws-lambda,ioexception,aws-documentdb,C#,Amazon Web Services,Aws Lambda,Ioexception,Aws Documentdb,我正试图从C#Lambda函数连接到AWSDocumentDB 问题是它在DocumentDB上启用了TLS,需要我向本地存储添加证书 如果我在EC2上运行,这很好,因为它需要对本地文件系统进行读/写访问 由于我运行的是Lambda,我不确定如何实现这一点 我在Lambda中尝试了示例代码,得到了以下IOException(因为它需要读/写访问): 无法将X509证书添加到存储。CryptographicException 在Internal.Cryptography.Pal.Director

我正试图从
C#
Lambda
函数连接到
AWS
DocumentDB

问题是它在
DocumentDB
上启用了
TLS
,需要我向本地存储添加证书

如果我在
EC2
上运行,这很好,因为它需要对本地文件系统进行
读/写访问

由于我运行的是
Lambda
,我不确定如何实现这一点

我在Lambda中尝试了示例代码,得到了以下IOException(因为它需要读/写访问):

无法将X509证书添加到存储。
CryptographicException
在Internal.Cryptography.Pal.DirectoryBasedStoreProvider.Add(ICertificatePal certPal)中
位于System.Security.Cryptography.X509Certificates.X509Store.Add(X509Certificate2证书)
在/build\u和部署/src/Lambdas/DependencyRegistar.cs中的Lambdas.DependencyRegistar.ConfigureMongoDatabase()处:第113行
在/build_和部署/src/Lambdas/DependencyRegistar.cs中的Lambdas.DependencyRegistar.ConfigureServices(IServiceCollection服务):第35行
在/build_和部署/src/Lambdas/Handlers/BaseLambdaHandler.cs中的Lambdas.handler.BaseLambdaHandler..ctor(IServiceCollection服务):第36行

-->只读文件系统:IOException我可以通过忽略SSL验证来解决这个问题:var settings=MongoClientSettings.FromUrl(new-MongoUrl(connectionString));如果(EnvironmentVariables.MongoDb.SSLEnabled){settings.SslSettings=new SslSettings(){checkCertificateRequest=false,ServerCertificateValidationCallback=(o,c,ch,er)=>true,};ServicePointManager.ServerCertificateValidationCallback+=(o,c,ch,er)=>true;}这是一个有效的问题,我很惊讶在Lambda中将自定义证书导入信任存储时没有那么多好的资源。如果您找到了信任证书的正确方法,而不是禁止端点验证,请告诉我。您可能希望检查您的Lambda是否位于VPC中,该VPC具有允许documentDb和Lambda之间通信的适当安全组。
The X509 certificate could not be added to the store.: CryptographicException
at Internal.Cryptography.Pal.DirectoryBasedStoreProvider.Add(ICertificatePal certPal)
at System.Security.Cryptography.X509Certificates.X509Store.Add(X509Certificate2 certificate)
at Lambdas.DependencyRegistar.ConfigureMongoDatabase() in /build_and_deploy/src/Lambdas/DependencyRegistar.cs:line 113
at Lambdas.DependencyRegistar.ConfigureServices(IServiceCollection services) in /build_and_deploy/src/Lambdas/DependencyRegistar.cs:line 35
at Lambdas.Handlers.BaseLambdaHandler..ctor(IServiceCollection services) in /build_and_deploy/src/Lambdas/Handlers/BaseLambdaHandler.cs:line 36

--> Read-only file system: IOException <--
at System.IO.FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at Internal.Cryptography.Pal.DirectoryBasedStoreProvider.AddCertToStore(ICertificatePal certPal)
at Internal.Cryptography.Pal.DirectoryBasedStoreProvider.Add(ICertificatePal certPal)