5
votes

Is there a way to connect Redis instance hosted on AWS from outside AWS network? I have one Windows based EC2 instance running on AWS and another one is Redis cache node.

I know this question has been asked but the answer is in context of Linux based system, but mine is Windows based server on AWS. I don't have enough score to post comments on existing questions. Here is the link to existing question on Stack Overflow:

Can you connect to Amazon Elasticache Redis outside of Amazon

1
Ok, I figured it out. You can use netsh commands to setup TCP Proxy on Windows Server. Here is the link where I got help: sysbiosis.com/blog/set-tcp-proxy-windows By default REDIS runs on Port 6379. So in my Inbound ports on AWS Security Group, I defined another port (6377) and fired below command netsh interface portproxy add v4tov4 listenaddress=LOCAL_IP_ADDRESS listenport=6377 connectaddress=IP_ADDRESS_OF_AWS_REDIS_INSTANCE connectport=6379 I hope it helps someone. Please don't forget to upvote, if it helps you. Can't post it as answer, bad score in my account.Manoj Aggarwal
if you think that's fix your own problem, you can answer it, and mark it accepted.BMW
I don't have enough numbers in my account to even answer my question and mark it accepted. Over designed by stack overflow :(Manoj Aggarwal
why do you need to redirect/proxy ports? Are you running a local redis node too?tedder42
Redis on AWS are accessible from EC2 instances only, that is the reason I need port redirection from EC2 to REDIS instance.Manoj Aggarwal

1 Answers

2
votes

Steps to access Elasticache Redis from outside of AWS.

1) Create an EC2 instance in same VPC as elasticache redis but the public subnet. Make sure that IP forwarding is enabled:

cat /proc/sys/net/ipv4/ip_forward

value ip_forward=1 indicates that forwarding is enabled

Make sure Masquerading is enabled: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

2) Create security Group with Inbound connection on port that you intend to forward ( lets say 6379 in this case). Specify the source CIDR block for the incoming connection. Ensure that the outbound rule allows connection to the redis cluster on desired port(default redis port is 6379)

3) Add IP table rule to allow forwarding rule from EC2 instance to elasticache iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 11211 -j DNAT --to :6379

source