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