Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to AWS Redis endpoint using redis-cli. Connection timed out

I created cache.t2.small Redis under ElastiCache. It's available.

I have the endpoint: portal-test.abcdef.ab.0001.abcd1.cache.amazonaws.com.

I ssh'ed to the instance (tried via ubuntu@ip-172-xx-xx-xx and runcloud@ip-172-xx-xx-xx). I'm trying to connect via redis-cli by typing:

redis-cli -h portal-test.abcdef.ab.0001.abcd1.cache.amazonaws.com -p 6379 ping

I expect PONG but instead I get

Could not connect to Redis at portal-test.abcdef.ab.0001.abcd1.cache.amazonaws.com:6379: Connection timed out

I went into my EC2 instance and defined the inbound traffic for port 6379:

enter image description here

On runcloud (that I used for this instance) I also opened the port and successfully deployed the firewall rules:

enter image description here

Same timeout. What am I missing?

like image 841
Matt Komarnicki Avatar asked Jan 08 '19 03:01

Matt Komarnicki


People also ask

Could not connect to Redis at AWS?

Confirm the security group on the ElastiCache cluster Select the cluster name from the Redis clusters menu, and then select the Network and security tab. 2. Verify that at least one of the associated security groups allows inbound connections from the client resource to the cluster on the cluster's port.

Could not connect to Redis at Redis?

Firewall restriction is another common reason that can trigger the “could not connect to Redis connection refused”. By default Redis server listen to the TCP port 6379. If another application is using the port or if the firewall restrictions blocks the port, it can trigger the connection refused error.

How connect AWS to Redis?

Sign in to the AWS Management Console and open the ElastiCache console at https://console.aws.amazon.com/elasticache/ . From the navigation pane, choose Redis clusters. The clusters screen will appear with a list of Redis (cluster mode disabled) and Redis (cluster mode enabled) clusters.

How do I connect to Redis command?

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.


2 Answers

I've found the solution.

Culprit:

Redis I created was not in the same VPC / Availability Zone / Subnet as the EC2 instance where my Laravel app lives. First one had IP 10.x.x.x > while the EC2 instance was 172.x.x.x. I assume this mismatch was preventing both ends to talk to each other. 🧠 🧠 🧠

Solution:

When you create Redis, simply assign it to the same VPC as your existing EC2 instance where your Laravel baby lives. Also reuse the same security group where you open port 6379 (assuming you picked this port as a default one when creating your Redis).

Now SSH into you EC2 and from within type:

redis-cli -h endpoint-from-your-aws-redis-dashboard -p 6379 ping

If you get:

PONG

you're the winner.

like image 60
Matt Komarnicki Avatar answered Oct 21 '22 09:10

Matt Komarnicki


Matt's answer lead me in the right direction. However, a small adjustment made my connection work. I looked over the security groups and I noticed that the security group that I had open connections to (i.e.Custom TCP 6379) wasn't bound to my ElastiCache Redis instance.

To modify your security groups in your ElastiCache Instance:

  • Click on your instance (make sure its highlighted)
  • Click on the Actions Dropdown Menu
  • Modify
  • VPC Security Groups (click on pencil icon)
  • Select Security Groups & Save
  • Finally, click on Modify

Wait until your ElastiCache Instance is done modifying then ssh into your EC2 Instance. Finally, try Matt's ping pong method.

Hope it helps!

like image 44
Asai Andrade Avatar answered Oct 21 '22 10:10

Asai Andrade