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?
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:
Create and import a certificate of authority using the AWS Certificate Manager. You will use this certificate to authorize your VPN connection.
Create a VPN Client Endpoint and attach the key and certificate generated in the previous step with it.
Associate the VPC being used on your elasticache cluster with the VPN endpoint.
Authorize all traffic on your VPN for all users.
Add a route to the route table of your VPN endpoint to allow access from anywhere (0.0.0.0/0).
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"!