This is a complete guide for installation and connection to Amazon ElastiCache Redis, covering both local testing with Redis CLI and cloud-based connection via EC2.
Amazon ElastiCache for Redis is a fully managed in-memory data store and cache service. It’s widely used to boost web application performance by reducing latency through fast, in-memory data retrieval.
-
Go to AWS Console → ElastiCache → Redis → Create Cluster
-
Choose:
- Cluster Mode: Disabled (single node) or Enabled (sharded)
- Node type:
cache.t3.micro
(Free tier eligible) - Replicas: Optional
- VPC: Select existing VPC
- Subnet group: Default or custom
- Security group: Add inbound port 6379 (from EC2's SG)
-
Enable Redis Auth Token (recommended for security)
-
Click Create
Modify Security Group attached to Redis:
-
Inbound Rule:
- Type: Custom TCP
- Port: 6379
- Source: EC2 Security Group or specific IP
- Ensure it’s in the same VPC and subnet as Redis
- Use Amazon Linux 2 or Ubuntu
sudo yum update -y
sudo yum install curl tar pip gcc jemalloc-devel -y
pip install redis
curl -O http://download.redis.io/redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
cd redis-stable
make
sudo cp src/redis-cli /usr/local/bin/
sudo apt update -y
sudo apt install redis-tools -y
- Go to ElastiCache Console → your cluster → Configuration endpoint
redis-cli -h your-cluster-endpoint.amazonaws.com -p 6379
redis-cli -h your-cluster-endpoint.amazonaws.com -p 6379 -a your_redis_password
redis6-cli --tls -h myredis-wjptpw.serverless.use1.cache.amazonaws.com -p 6379
Use
redis6-cli
for TLS-based Serverless Redis connections
set greeting "Hello from Redis"
get greeting
del greeting
set x hello
get x
- 🔒 Use Redis AUTH in all environments
- 🚫 Do NOT expose Redis to the public internet
- 🔐 Use Security Groups and VPC isolation
- 📈 Monitor using Amazon CloudWatch
pip install redis
import redis
r = redis.StrictRedis(
host='your-cluster-endpoint.amazonaws.com',
port=6379,
password='your_redis_password', # Optional if AUTH is not enabled
decode_responses=True
)
r.set('framework', 'flask')
print(r.get('framework'))