Aaron Mednick
Aaron Mednick

Reputation: 660

Cannot Connect To AWS Elasticache Redis Cluster From Local Machine

I recently created a Redis cluster on AWS elasticache and am having trouble connecting via redis-cli from my local machine. Every time I run the command:

redis-cli -h <redis_cluster_domain> -p 6379

the connection is never established and eventually exits due to timeout.

Eventually, I figured it's blocking due to a setting on the security group, so I edited the inbound rules to allow all traffic from my IP address. Even after doing this I still cannot connect to the cluster. Any ideas why this might be?

Upvotes: 7

Views: 21546

Answers (4)

Vishwas Shashidhar
Vishwas Shashidhar

Reputation: 837

For posterity, if you are trying to connect through a resource from the same VPC and still not able to connect, you may need to pass the --tls option in the command line with redis-cli if you've enabled encryption in transit on your redis cluster.

More details here -> https://repost.aws/knowledge-center/elasticache-redis-cluster-fix-connection

Upvotes: 0

Sagar
Sagar

Reputation: 41

Probably you need to edit the Inbound rule in Network&Security of the Redis cluster. Also if you are using VPN, please ensure if you have made a TCP protocol entry.

Upvotes: 0

Devqxz
Devqxz

Reputation: 111

you can also do this via a jump server / bastion host and even local port forwarding.

Upvotes: 3

Aaron Mednick
Aaron Mednick

Reputation: 660

I figured it out.

Apparently, you cannot access elasticache clusters from outside AWS by default. In order to do this, you need to create a VPN through AWS and connect to that in order to reach your desired cluster.

The steps to do this are outlined in this AWS tutorial here, but in more simple terms all I did was the following:

  1. Create and import a certificate of authority using the AWS Certificate Manager. You will use this certificate to authorize your VPN connection.

  2. Create a VPN Client Endpoint and attach the key and certificate generated in the previous step with it.

  3. Associate the VPC being used on your elasticache cluster with the VPN endpoint.

  4. Authorize all traffic on your VPN for all users.

  5. Add a route to the route table of your VPN endpoint to allow access from anywhere (0.0.0.0/0).

  6. Download VPN client configuration file locally and connect to the VPN using "openvpn" (you may need to brew install this) with your certificate and key created in the first step.

This worked for me and I'm glad I figured it out. Now I can connect to my Redis cluster from my local machine using "redis-cli"!

Upvotes: 15

Related Questions