简体   繁体   English

AWS Lambda使用.NET Core和Google表格API

[英]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.

相关问题 AWS Lambda和.NET Core-使用Linux运行时吗? - AWS Lambda and .NET Core - Using a Linux Runtime? 如何:使用AWS Cognito的C#.net核心API(APIGateway / Lambda)+ Xamarin + Facebook身份验证 - How To: C# .net core API (APIGateway/Lambda) + Xamarin + Facebook authentication using AWS Cognito 无法将 AWS Lambda 中的 .net 核心 API 连接到 RDS - Cannot connect .net core API in AWS Lambda to RDS .NET Core Web API only gets JSON from the Mock Lambda Tool. 使用 Postman、Swagger 和 AWS Lambda 失败 - .NET Core Web API only gets JSON from the Mock Lambda Tool. Using Postman, Swagger & AWS Lambda fail 发布AWS Lambda .Net Core - Publishing AWS Lambda .Net Core .net core aws Lambda没有错误,但Lambda暂停 - .net core aws Lambda No error, but Lambda halts 将自定义 AWS Lambda 运行时与 asp.net 核心结合使用 - Using Custom AWS Lambda Runtimes with asp.net core 在AWS Lambda中使用.NET Core读取Excel文件 - Read excel file using .NET core in aws lambda Return File from AWS ApiGateway ASP.NET Core 3 Web API running as AWS Lambda function - Return File from AWS ApiGateway ASP.NET Core 3 Web API running as AWS Lambda function 带有 .Net 核心的 AWS Lambda - 为 IOptions 启用注入? - AWS Lambda with .Net core - Enabling Injection for IOptions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM