title: How to connect AWS Elasticache Redis cluster to Spring Boot app?
body: <p>I have Spring Boot app which connects to Redis cluster, using Jedis Connection Factory:</p>
  
  <pre class="lang-java prettyprint-override"><code>RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(redisProperties.getCluster().getNodes());
  redisClusterConfiguration.setPassword(redisProperties.getPassword());
  jedisConnectionFactory = new JedisConnectionFactory(redisClusterConfiguration);
  </code></pre>
  
  <p>and reading list of nodes from application.yml:</p>
  
  <pre><code>spring:
    redis:
      host: 127.0.0.1
      port: 6379
      timeout: 300s
      cluster:
        nodes: 127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6382
  </code></pre>
  
  <p>Now we want to switch to Elasticache since we are hosting our Redis cluster on AWS anyway.
  It would be done quite easily. If AmazonElastiCache lib could be used.
  Then we could just connect to Elasticache cluster with AWS credentials, pull available nodes put it in the list and pass it to Jedis instead hardcoding them in application.yml, like:</p>
  
  <pre class="lang-java prettyprint-override"><code>//get cache cluster nodes using AWS api
  private List&lt;String&gt; getClusterNodes(){
      AmazonElastiCache client = AmazonElastiCacheClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
      DescribeCacheClustersRequest describeCacheClustersRequest = new DescribeCacheClustersRequest();
      describeCacheClustersRequest.setShowCacheNodeInfo(true);
      List&lt;CacheCluster&gt; cacheClusterList = client.describeCacheClusters(describeCacheClustersRequest).getCacheClusters();
      List&lt;String&gt; nodeList = new ArrayList&lt;&gt;();
      try {
          for (CacheCluster cacheCluster : cacheClusterList) {
              for(CacheNode cacheNode :cacheCluster.getCacheNodes()) {
                  String nodeAddr = cacheNode.getEndpoint().getAddress() + ":" +cacheNode.getEndpoint().getPort();
                  nodeList.add(nodeAddr);
              }
          }
      }
      catch(Exception e) {
          e.printStackTrace();
      }
      return nodeList;
  }
  </code></pre>
  
  <p>But DevOps team said that they can't configure AWS access on all labs and they have reasons for it. Also instead of connecting to AWS and pulling all available clusters we need to connect to specific one by URL.</p>
  
  <p>So I tried to pass Elasticache cluster url directly to Jedis as standalone and as a cluster in application.yml configuration.
  In both cases connection is established, but when App tries to write to Elasticache its gets MOVED exception:</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.data.redis.ClusterRedirectException: Redirect: slot 1209 to 10.10.10.011:6379.; nested exception is redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 1209 10.10.10.102:6379
  </code></pre>
  
  <p>Which as I understand means that App tried to write to one of the nodes in Elasticache, but wasn't able to connect.</p>
  
  <p><strong>So the question would be is there a way to connect to Elasticache Redis cluster from Spring Boot app using only Elasticache cluster URL?</strong> </p>
  
  <p>I know that it's doable if Elasticache Memecache is used.
  Also Jedis driver is not a hard requirement.</p>
  
  <p>Thank you.</p>