I have the following AWS infrastructure,
- VPC
- ECS Fargate container running an ASP.net app
- MemoryDB Redis Cluster
- Elastic Beanstalk Spring Boot Web App using Spring Boot Redis
The problem is the Elastic Beanstalk Spring Boot app cannot connect to the MemoryDB cluster. It always fails with the following error
o.s.d.r.l.RedisMessageListenerContainer : Connection failure occurred.
I am able to connect to my local Redis from the Spring Boot App without any issues. Also, the ASP.net app running in ECS Fargate can connect to the MemoryDB cluster without any issues. Based on this I figured it would be relatively easy to get a Spring Boot app running in Elastic Beanstalk to connect to a MemoryDB cluster without too much trouble, boy was I wrong. I have gone over and over everything configuration related to the VPC and Elastic Beanstalk application. They are on the same VPC, they use the same subnet, they have the necessary inbound and outbound rules in the added security groups. I've added the security group created by the Elastic Beanstalk app to the MemoryDB cluster. I've tried connection through the JedisConnectionFactory with both normal and cluster configurations, I've tried with SSL on and off. I've read over the following Stackoverflow articles,
- Connect to Redis (AWS) from Elastic Beanstalk instance
- Connecting to AWS MemoryDB
- How to connect AWS Elasticache Redis cluster to Spring Boot app?
- How run docker redis in cluster mode?
- aws elastic beanstalk with spring boot app
- Use java Jedis connect to aws elasticache redis
- What format to use when entering an IP address into an EC2 Security Group rule?
- JedisCluster : redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reachable node in cluster
I did not find anything helpful in any of these articles. It seems to me that there is no documentation anywhere that outlines a simple base example of how to connect a Spring Boot app running in Elastic Beanstalk to an AWS MemoryDB Redis cluster.
My RedisConfig Jedis connection factory creations functions
At this point it seems to me the problem is very likely AWS related but I cannot be certain as I don't even know what else to try at this point since I can connect without issue from ECS Fargate and from my local development environment to a local redis db. Does anyone have any suggestions or a very simple tutorial on how to connect a Springboot App running in Elastic Beanstalk to a MemoryDB cluster?
EDIT 1 After looking at the Elastic Beanstalk stdout web log im seeing this error when I use RedisClusterConfiguration connection method
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: No reachable node in cluster; nested exception is redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reachable node in cluster] with root cause Jul 4 17:15:53 ip-172-31-26-91 web: redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reachable node in cluster Jul 4 17:15:53 ip-172-31-26-91 web: at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnection(JedisSlotBasedConnectionHandler.java:86) ~[jedis-3.3.0.jar!/:na] Jul 4 17:15:53 ip-172-31-26-91 web: at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:103) ~[jedis-3.3.0.jar!/:na]
Also in the nginx error log from beanstalk im seeing this
connect() failed (111: Connection refused) while connecting to upstream, client: 73.33.4.162, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "odyssey-env.eba-yq3g2trt.us-east-1.elasticbeanstalk.com"
Edit 2 When I use RedisStandaloneConfiguration to connect I get this error,
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause Jul 4 17:59:26 ip-172-31-26-91 web: java.net.ConnectException: Connection refused (Connection refused)