If you are trying to connect to ElastiCache from your local machine which is outside AWS, you need to create a Network Address Translation (NAT) instance in the same VPC as the ElastiCache cluster and connect to the NAT instance from your application. The NAT instance acts as a proxy between your application and the Elasticache cluster. These are the steps -
- Create a NAT instance in the same VPC as your cache cluster but in a public subnet. An Elastic IP Address (EIP) must be associated with the NAT instance. The port forwarding feature of iptables is used to forward a port on the NAT instance to the cache node port within the Amazon VPC.
Create the following security group rules for the NAT instance and ElastiCache cluster -
- NAT instance security group - inbound - access to the cluster port from your application IP (eg., 6379 in case of Redis)
- NAT instance security group - inbound - SSH access from a trusted IP (port 22)
- NAT instance security group - outbound - access to ElastiCache cluster port (eg., 6379 in case of Redis) by specifying destination as Elasticache security group
- Elasticache security group - inbound - access from NAT instance security group on cluster port (eg., 6379 in case of Redis) by specifying source as NAT instance security group
Add an iptables rule to the NAT instance. An iptables rule must be added to forward the cache port from the NAT instance to the cluster node. There should be one rule for each node in the cluster . An example for Redis might look like the following:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 6379 -j DNAT --to <cluster-node-ip>:6379
- The application residing outside AWS can now connect to the EastiCache cluster using the EIP of the NAT instance and the cluster port.
More information can be found here -
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html
An alternative is to deploy your application containing the Redisson client on a EC2 instance (preferably within the same VPC as ElastiCache). You can then connect to ElastiCache from that application.