2

J'essaie d'exploiter AWS Elasticache (Redis) à partir de ma fonction Lambda à l'aide de la bibliothèque ServiceStack .Redis.Core (version 1.0.44). Lors de l'exécution de la lambda à partir de ma machine locale (mac osx) tout fonctionne bien; Je peux interagir avec le cache AWS Redis sans erreur.ServiceStack Redis ne fonctionne pas sur AWS Lambda

Cependant, quand je déploie ma fonction à AWS pour exécuter sur leurs serveurs lambda le code ne fonctionne plus et la bibliothèque ServiceStack.Text.Env jette une exception 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()" 
     ] 
    } 
    } 
} 

Ainsi est-il possible d'utiliser le package ServiceStack.Redis.Core lors de l'exécution dans AWS Lambda?

+1

Avez-vous construit votre application sur OSX et l'avez-vous téléchargée sur Lambda? – dashmug

+0

oui, il a été construit sur mon mac ciblant le framework .NET Standard 1.6. FWIW tout le reste dans le lambda fonctionne bien. Ce n'est que lorsque le code déclenche une interaction avec ServiceStack.Redis qu'il lance cette exception. – Jez

+0

Lambda fonctionne sur Linux, donc je pense que vous devriez compiler votre code sur une machine Linux et télécharger ce code compilé vers Lambda. – dashmug

Répondre

3

Cette exception est due à AWS Lambda qui ne met pas en œuvre l'API RuntimeInformation.IsOSPlatform(OSPlatform.Linux) de .NET Core pour détecter le système d'exploitation sur lequel l'application est exécutée.

J'ai juste added a fix to catch cette API non implémentée qui est disponible à partir de la version 4.5.15 qui est maintenant available on MyGet.

+1

Le nouveau package a bien fonctionné! Merci! – Jez