[英]AWS Lambda using .NET Core and Google Sheets API
I'm writing an Alexa skill that uses an AWS Lambda function using the C# runtime (.NET Core), and am trying to connect to a Google Sheet using their API. 我正在编写使用C#运行时(.NET Core)的AWS Lambda函数的Alexa技能,并尝试使用其API连接到Google表单。 It throws a missing DLL exception during runtime: 它在运行时抛出一个丢失的DLL异常:
The type initializer for 'System.Security.Cryptography.CngKeyLite' threw an exception. 'System.Security.Cryptography.CngKeyLite'的类型初始值设定项引发了异常。
at System.Security.Cryptography.CngKeyLite.ImportKeyBlob(String blobType, Byte[] keyBlob) 在System.Security.Cryptography.CngKeyLite.ImportKeyBlob(String blobType,Byte [] keyBlob)
at System.Security.Cryptography.RSAImplementation.RSACng.ImportKeyBlob(Byte[] rsaBlob, Boolean includePrivate) 在System.Security.Cryptography.RSAImplementation.RSACng.ImportKeyBlob(Byte [] rsaBlob,Boolean includePrivate)
at System.Security.Cryptography.RSAImplementation.RSACng.ImportParameters(RSAParameters parameters) 在System.Security.Cryptography.RSAImplementation.RSACng.ImportParameters(RSAParameters参数)
at Google.Apis.Auth.OAuth2.ServiceAccountCredential.Initializer.FromPrivateKey(String privateKey) at Google.Apis.Auth.OAuth2.ServiceAccountCredential.Initializer.FromPrivateKey(String privateKey)
at Google.Apis.Auth.OAuth2.DefaultCredentialProvider.CreateServiceAccountCredentialFromParameters(JsonCredentialParameters credentialParameters) at Google.Apis.Auth.OAuth2.DefaultCredentialProvider.CreateServiceAccountCredentialFromParameters(JsonCredentialParameters credentialParameters)
at Google.Apis.Auth.OAuth2.DefaultCredentialProvider.CreateDefaultCredentialFromParameters(JsonCredentialParameters credentialParameters) at Google.Apis.Auth.OAuth2.DefaultCredentialProvider.CreateDefaultCredentialFromParameters(JsonCredentialParameters credentialParameters)
at AlexaProjLib.GoogleSheet.Connect() 在AlexaProjLib.GoogleSheet.Connect()
at AlexaProj.Function.FunctionHandler(SkillRequest input, ILambdaContext context) 在AlexaProj.Function.FunctionHandler(SkillRequest输入,ILambdaContext上下文)
Inner exception: 内部异常:
Unable to load DLL 'ncrypt.dll': The specified module could not be found. 无法加载DLL'ncrypt.dll':找不到指定的模块。
Code: 码:
var credential = GoogleCredential.FromJson(_googleSecret).CreateScoped(_scopes);
Service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = _applicationName,
});
I'm pretty new to .NET Core and Lambda - how do I get the missing DLL correctly referenced? 我是.NET Core和Lambda的新手 - 如何正确引用丢失的DLL?
Try to follow the instructions provided in this github forum as other users encountered it also. 尝试按照此github论坛中提供的说明进行操作,其他用户也会遇到它。
execute
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
instead of
ln -s /usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib /usr/local/lib
ln -s /usr/local/Cellar/openssl/1.0.2h_1/lib/libssl.1.0.0.dylib /usr/local/lib
if you receive "File exists" message ln -sf will do the magic..
ln -sf /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -sf /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
The issue turned out to be that I was defining a Windows runtime in the project.json file (win10-x64), which was causing these runtime errors (AWS Lambda runs on Amazon Linux). 问题是我在project.json文件(win10-x64)中定义了一个Windows运行时,这导致了这些运行时错误(AWS Lambda在Amazon Linux上运行)。 Ended up getting it compiled and running by using dotnet lambda package , with more details here . 最后通过使用dotnet lambda包来编译和运行它, 这里有更多细节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.