2

我正在尝试使用ServiceStack .Redis.Core库(版本1.0.44)从我的Lambda函数中利用AWS Elasticache(Redis)。从本地机器(mac osx)运行lambda时,一切正常;我可以无误地与AWS Redis缓存进行交互。ServiceStack Redis不在AWS上运行Lambda

然而,当我部署我的功能AWS他们拉姆达服务器上执行代码不再工作和ServiceStack.Text.Env库抛出一个异常PlatformNotSupportedException:

{ 
    "errorType": "RedisException", 
    "errorMessage": "[13:50:14.793] Unable to Connect: sPort: 55382, Error: The type initializer for 'ServiceStack.Text.Env' threw an exception. 
    at ServiceStack.Redis.RedisNativeClient.FlushSendBuffer() 
    at ServiceStack.Redis.RedisNativeClient.SendReceive[T](Byte[][] cmdWithBinaryArgs, Func`1 fn, Action`1 completePipelineFn, Boolean sendWithoutRead)", 
    "stackTrace": [ 
    "at ServiceStack.Redis.RedisNativeClient.CreateConnectionError(Exception originalEx)", 
    "at ServiceStack.Redis.RedisNativeClient.SendReceive[T](Byte[][] cmdWithBinaryArgs, Func`1 fn, Action`1 completePipelineFn, Boolean sendWithoutRead)", 
    "at ServiceStack.Redis.RedisNativeClient.get_Info()", 
    "at ServiceStack.Redis.RedisClient.GetServerRole()", 
    "at ServiceStack.Redis.RedisResolver.CreateRedisClient(RedisEndpoint config, Boolean master)", 
    "at ServiceStack.Redis.RedisManagerPool.GetClient()", 
    **snip** 
    "at lambda_method(Closure , Stream , Stream , ContextInfo)" 
    ], 
    "cause": { 
    "errorType": "TypeInitializationException", 
    "errorMessage": "The type initializer for 'ServiceStack.Text.Env' threw an exception.", 
    "stackTrace": [ 
     "at ServiceStack.Redis.RedisNativeClient.FlushSendBuffer()", 
     "at ServiceStack.Redis.RedisNativeClient.SendReceive[T](Byte[][] cmdWithBinaryArgs, Func`1 fn, Action`1 completePipelineFn, Boolean sendWithoutRead)" 
    ], 
    "cause":  { 
     "errorType": "PlatformNotSupportedException", 
     "errorMessage": "Operation is not supported on this platform.", 
     "stackTrace": [ 
     "at System.Runtime.InteropServices.OSPlatform.get_Linux()", 
     "at ServiceStack.Text.Env..cctor()" 
     ] 
    } 
    } 
} 

所以是有可能使用在AWS Lambda中运行时的ServiceStack.Redis.Core包?

+1

您是否在OSX上构建应用程序并将其上载到Lambda? – dashmug

+0

是的,它建立在我的mac上,以.NET标准1.6框架为目标。 FWIW lambda中的其他所有内容都可以正常工作。只有当代码触发与ServiceStack.Redis的交互时,它才会抛出此异常。 – Jez

+0

Lambda在Linux上运行,因此我认为您应该在Linux机器上编译您的代码并将编译后的代码上传到Lambda。 – dashmug

回答

3

此异常是由于AWS Lambda未实施.NET Core的RuntimeInformation.IsOSPlatform(OSPlatform.Linux) API来检测应用程序在哪个操作系统上运行。

我刚刚added a fix to catch这个未实现的API,它是从v4.5.15现在是available on MyGet

+1

新包装效果很好!谢谢! – Jez