There are two scenario:
If you have an EC2 instance in the same subnet as your Redis Elasticache
- This will only work if the EC2 instance you connect to is in the same subnet as your Elasticache Redis instance.
- The following example will state that your Elasticache private IP is
172.31.5.13and is running on port
- The following example will state that your EC2 private IP is
172.31.5.14and its public IP is
- Connect to your EC2 instance through SSH
- Then run (don't forget to change
172.31.5.13:6379by the ElasticCache IP and port number)
sudo iptables -t nat -A PREROUTING -p tcp --dport 6379 -j DNAT --to-destination 172.31.5.13:6379
- Then run:
172.31.5.14with your local EC2 server private IP. Same goes for
6379, replace them your Elasticache IP and port number.
220.127.116.11, protocol=TCP, port=
- Add a new "Redis server is exposed to internet" in redsmin with the connection string:
- If you have any issue or questions with the above steps, don't hesitate, contact us, we are happy to help!
- Don't forget to allow forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
- And activate it directly (no need for reboot):
sysctl -w net.ipv4.ip_forward=1Optional checks before connecting to Redsmin:
- You should now be able to connect from your EC2 gateway to your redis elasticache using redis-cli.
- You should now be able to connect to your Elasticache instance through your EC2 gateway from your local laptop using redis-cli.
If you don't have an EC2 instance in the same subnet as your Redis ElastiCache
- Follow this Amazon tutorial to setup a NAT instance, be sure to setup it on the same subnet as your ElastiCache server.
- Now follow the steps from the section above.