ServiceStack Redis 在 AWS Lambda 上没有 运行

ServiceStack Redis does not run on AWS Lambda

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

但是,当我将函数部署到 AWS 以在他们的 lambda 服务器上执行时,代码不再有效并且 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 包?

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

我刚 added a fix to catch this non implemented API which is available from v4.5.15 that's now available on MyGet.