1

I am connecting .NET core app to AWS ElastiCache Redis. enter image description here

The AWS Elasticache Redis is running and port 6329 is open on security group. The client code is using StackExchange.Redis:

           var redis = ConnectionMultiplexer.Connect("redis-1.xxxx.0001.use1.cache.amazonaws.com:6379");
           //var redis = ConnectionMultiplexer.Connect("localhost"); //working
           IDatabase db = redis.GetDatabase();

            string value = "abcdefg";
            db.StringSet("mykey", value);        

            string value2 = db.StringGet("mykey");
            Console.WriteLine(value2); // writes: "abcdefg"

            Console.ReadLine();

Exception is:

It was not possible to connect to the redis server(s). UnableToConnect on redis-1.xxx.0001.use1.cache.amazonaws.com:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 5s ago, last-write: 5s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.0.601.3402

Added to ,abortConnect=false to the endpoint, I am able to connect.

Now the error is at StringSet

StackExchange.Redis.RedisConnectionException: 'No connection is available to service this operation: SET mykey; UnableToConnect ...

The .NET code is working fine with my local Redis service so looks like something incorrect with my AWS setup.

Successfully ssh to my EC2-instance and redis-cli to my AWS redis service: enter image description here

Any idea please?

NOTE: AWS Elasticache Redis is NOT available for public access as default.

beewest
  • 4,486
  • 7
  • 36
  • 63
  • Maybe try connecting to the server using redis-cli from your workstation? – Trinopoty Mar 14 '20 at 08:26
  • successfully ssh into a ec2-instance and run redis-cli againt my aws redis service. But still failed from .net app (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/GettingStarted.ConnectToCacheNode.html) – beewest Mar 14 '20 at 10:09
  • Just to be clear, you're getting this error when you deploy your code to the same EC2 instance? In that case, there shouldn't be any issues since the redis-cli can connect fine. – Trinopoty Mar 14 '20 at 10:18
  • I am running .net code from my machine. Thought `redis-1.xxxx.0001.use1.cache.amazonaws.com:6379` is public available via security group (TCP\6379 for All IPs)? – beewest Mar 14 '20 at 10:23
  • Try to connect to your redis server from your own machine then with redis-cli, not from the EC2. – Trinopoty Mar 14 '20 at 10:25
  • Also, if your redis cluster does not have a public IP address, you cannot connect to it remotely even if you have the proper rules enabled. So check for that maybe. It's difficult to tell without knowing the actual hostname. – Trinopoty Mar 14 '20 at 10:32
  • Failed to run redis-cli to redis-1.xxxx.0001.use1.cache.amazonaws.com:6379 from my machine. – beewest Mar 14 '20 at 10:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/209622/discussion-between-trinopoty-and-beewest). – Trinopoty Mar 14 '20 at 10:34

1 Answers1

0

Question: "...port 6329 is open on security group.." Dont you mean 6379?

Even that, i think i cn have an issue on the "default" subnet groups.

Does the VPC_Subnet (in that group) where the AWS ElastiCache Redis is, has a Routing Table with access to the Internet Gateway? If not, you need to attache the InternetGteway to the Route Table and than use that Route Table on the Subnet that you want.

It should be like the pick: Internet GW

b4ld
  • 26
  • 4