2

I am trying to leverage AWS Elasticache (Redis) from my Lambda function using the ServiceStack .Redis.Core library (version 1.0.44). When running the lambda from my local machine (mac osx) everything works fine; I can interact with the AWS Redis cache with no errors.

However, when I deploy my function to AWS to execute on their lambda servers the code no longer works and the ServiceStack.Text.Env library throws a PlatformNotSupportedException exception:

{
  "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()"
      ]
    }
  }
}  

So is it possible to use the ServiceStack.Redis.Core package when running in AWS Lambda?

Jez
  • 100
  • 5
  • 1
    Did you build your application on OSX and uploaded it to Lambda? – Noel Llevares Sep 25 '17 at 14:29
  • yes, it was built on my mac targeting the .NET Standard 1.6 framework. FWIW everything else in the lambda works fine. Only when the code triggers interaction with ServiceStack.Redis does it throw this exception. – Jez Sep 25 '17 at 14:50
  • Lambda runs on Linux so I think you should compile your code on a Linux machine and upload that compiled code to Lambda. – Noel Llevares Sep 25 '17 at 14:54

1 Answers1

3

This Exception is due to AWS Lambda not implementing .NET Core's RuntimeInformation.IsOSPlatform(OSPlatform.Linux) API for detecting which OS the App is being run on.

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

mythz
  • 141,670
  • 29
  • 246
  • 390