Finding AWS ElastiCache Endpoints Using Java

I am trying to programmatically retrieve the ElastiCache endpoint list from my Java application using the latest Java AWS SDK. Everything seems to not work - I can find a valid CacheCluster, but then when I list its nodes, it is empty. Here is my code:

CacheCluster cc = it.next(); System.out.println("Cache node type: " + cc.getCacheNodeType()); System.out.println("Number cache nodes: " + cc.getNumCacheNodes()); List<CacheNode> listCache = cc.getCacheNodes(); System.out.println("List size: " + listCache.size()); 

When I run it, I get the following output:

 Cache node type: cache.m1.small Number cache nodes: 1 List size: 0 

It seems so simple but doesn't seem to work. I started the ElastiCache cluster with one node, but when I getCacheNodes (), the list becomes empty. I tried to run this code locally and on an EC2 instance, and I get the same thing both times.

Any ideas on what I might be doing wrong?

+6
source share
1 answer

According to the response of the AWS command to Unable to retrieve cache nodes from the ElastiCache cluster , you will need to use the optional ShowDetails flag to get CacheNodes Information through the DescribeCacheClustersRequest class parameter of the method to describe CacheClusters () . If you look closer, the ShowDetails checkbox is missing, despite the fact that it is actually documented for this class:

The optional ShowDetails flag can be used to retrieve detailed information about the cache nodes associated with the cache cluster. Details include the DNS address and port for the Cache Node endpoint.

Presumably, this actually targets setShowCacheNodeInfo () , which is an optional flag that can be included in a DescribeCacheCluster request to get information about cache nodes.

Thus, the response from the AWS command seems inaccurate and does not really solve the question of why the getCacheNodes () method from Class CacheCluster does not return this information, and this is rather unusual for such messages.

In any case, you can simply try the getCacheNodes () method from the CacheCluster class returned by the getCacheClusters () method from the DescribeCacheClustersResult class , I hope it works as advertised (i.e. I have not tried it myself).

Good luck


Update

Here is the code that Sander has successfully used to achieve its goal, confirming the approach described above:

 AmazonElastiCacheClient client = new AmazonElastiCacheClient(credentials); DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest(); dccRequest.setShowCacheNodeInfo(true); DescribeCacheClustersResult clusterResult = client.describeCacheClusters(dccRequest); 

The missing fragments should be similar to its initial solution, for example:

 List<CacheCluster> cacheClusters = clusterResult.getCacheClusters(); for (CacheCluster cacheCluster : cacheClusters) { List<CacheNode> cacheNodes = cacheCluster.getCacheNodes(); System.out.println("List size: " + cacheNodes.size()); } 
+7
source

Source: https://habr.com/ru/post/910632/


All Articles