Connecting to ElastiCache (Outside VPC) instance from a EC2 inside VPC

可紊 提交于 2019-12-23 03:54:25

问题


We have large number of applications that uses one ElasticCache instance (Redis) which is located outside the VPC (a classic instance). Some Applications are located with in VPCs and Some are outside VPC (Classic instances). How can we connect all applications to the cache ?

We have no issue connecting applications outside VPC to the cache as the cache is also located outside VPC There is a smaller number of applications inside VPCs that cannot connect to the cache.

Thanks.


回答1:


Its is not possible to directly access the classic-cluster from a VPC instance. The workaround would be configuring NAT on the classic instance.

NAT need to have a simple tcp proxy

YourIP=1.2.3.4
YourPort=80
TargetIP=2.3.4.5
TargetPort=22

iptables -t nat -A PREROUTING --dst $YourIP -p tcp --dport $YourPort -j DNAT \
--to-destination $TargetIP:$TargetPort
iptables -t nat -A POSTROUTING -p tcp --dst $TargetIP --dport $TargetPort -j SNAT \
--to-source $YourIP
iptables -t nat -A OUTPUT --dst $YourIP -p tcp --dport $YourPort -j DNAT \
--to-destination $TargetIP:$TargetPort

More details: https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html



来源:https://stackoverflow.com/questions/38066908/connecting-to-elasticache-outside-vpc-instance-from-a-ec2-inside-vpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!