Learn how to connect Redis CLI to AWS ElastiCache easily using SSH tunneling or EC2 proxy with all commands and setup details included. Our Live Support team is always here to help you. 

How to Use Redis CLI to Connect to AWS ElastiCache

Connecting Redis CLI to AWS ElastiCache can seem confusing at first because AWS keeps its Redis clusters secured inside private networks. Still, with the right setup and a few commands, you can connect without a hitch. Let’s go through every working method, no unnecessary talk, just what matters.

redis cli connect to aws elasticache

Installing Redis CLI

Start by installing the Redis CLI tools on your system. On Debian-based systems like Ubuntu, this is quick and direct (see complete instructions to install Redis on Debian 12/11):

sudo apt-get -y update; \
sudo apt-get -y upgrade; \
sudo apt-get -y install redis-tools; \
redis-cli --version

Note that this installs the Redis command-line tools, not the server itself.

Connect Redis CLI to AWS ElastiCache

Once installed, you can connect directly to your AWS ElastiCache endpoint using the -h flag. If authentication is enabled, include -a for the password.

redis-cli -h my.url.to.redis.cache.amazonaws.com

If your Redis instance runs on a different port, use -p, or pass the full connection URL:

redis-cli -u redis://my.url.to.redis.cache.amazonaws.com:1234

Useful Redis Queries

Here are several practical queries you can use right after connecting:

# list all keys spaces
echo INFO keyspace | redis-cli -h my.url.to.redis.cache.amazonaws.com
# list all keys inside the Redis instance
redis-cli -h my.url.to.redis.cache.amazonaws.com --scan
# list all keys inside a Redis DB2
redis-cli -h my.url.to.redis.cache.amazonaws.com -n 2 --scan
# lists the keys that are big
redis-cli -h my.url.to.redis.cache.amazonaws.com --bigkeys
# counts the number of keys:
echo DBSIZE | redis-cli -h my.url.to.redis.cache.amazonaws.com

Accessing ElastiCache from Local Machine

Connecting Redis CLI to AWS ElastiCache from your local system often requires a few extra steps since AWS restricts direct external access. The best ways are through SSH tunneling or by using an EC2 proxy.

Option 1: SSH Tunneling

Launch an EC2 instance in the same VPC as your ElastiCache cluster. Make sure its security group allows inbound SSH from your IP. Then, open an SSH tunnel:

ssh -i "your-keypair.pem" -L local_port:redis_endpoint:redis_port ec2-user@ec2_instance_public_ip

Replace each placeholder with your actual details. Once the tunnel is active, connect locally:

import redis
client = redis.Redis(host='localhost', port=local_port)
client.ping() # Should return True if connected successfully
Option 2: EC2 as a Proxy

You can also connect through an EC2 instance directly. First, install Redis CLI on your EC2 machine:

sudo amazon-linux-extras install redis4.0

Next, log in:

ssh -i "your-keypair.pem" ec2-user@ec2_instance_public_ip

Then connect to your ElastiCache Redis:

redis-cli -h redis_endpoint -p redis_port

Aligning Security Groups

If your connection still times out, it’s most likely due to mismatched security groups.

  • Go to ElastiCache Dashboard → Redis and click your cluster name.
  • Copy the Security Group ID.
  • Visit EC2 → Network & Security → Security Groups and find the same group.
  • Under EC2 → Instances, check your instance’s security groups.
  • Add the matching group if missing via Actions → Networking → Change Security Groups.

Once both share the same group, reconnect:

redis-cli -c -h mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com -p 6379 ping

For Encrypted Connections

If encryption in transit is enabled, include the –tls flag along with authentication:

redis-cli -h <primary endpoint> --tls -p <port> -a <password> <optional command>

For example:

redis-cli -h master.redis.abc7bh.usw2.cache.amazonaws.com --tls -p 6379 -a password ping

You can also run Redis CLI using Docker:

docker run -it redis:6.2.6 /bin/bash

Then use the same Redis command inside the container.

[If needed, Our team is available 24/7 for additional assistance.]

Conclusion

Connecting Redis CLI to AWS ElastiCache becomes effortless once you configure the security groups and understand the flags. These commands work consistently across versions and setups. Follow them precisely, and you’ll have a clean, working Redis connection in no time.