Question

I'm trying to programmatically get a list of ElastiCache endpoints from my Java app using the latest Java AWS SDK. Things don't seem to be working - I can find a valid CacheCluster, but then when I list its nodes, it's empty. Here's 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

This seems so simple, but doesn't seem to work. I have started an ElastiCache cluster with a single node, but the list comes up empty when I call getCacheNodes(). I've tried to run this code locally and on an EC2 instance, and I get the same thing both times.

Any ideas on what I could be doing wrong?

Was it helpful?

Solution

According to the AWS team response to Not able to get cache nodes from ElastiCache cluster you'll need to use optional ShowDetails flag to obtain CacheNodes Information via the Class DescribeCacheClustersRequest parameter of method describeCacheClusters(). Looking closer there is no ShowDetails flag though, despite being documented for this class indeed:

An 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 the DescribeCacheCluster request to retrieve Cache Nodes information.

So the AWS team response seems imprecise and actually isn't addressing the question, why method getCacheNodes() from Class CacheCluster isn't returning that information, both being pretty unusual for such posts.

Anyway, you might simply want to try method getCacheNodes() from Class CacheCluster as returned by method getCacheClusters() from Class DescribeCacheClustersResult instead, hopefully it works as advertized (i.e. I haven't tried this myself).

Good luck!


Update

Here is the code Sander used successfully to achieve his goal, confirming the approach outlined above:

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

DescribeCacheClustersResult clusterResult = client.describeCacheClusters(dccRequest);

The missing pieces should be similar to his initial solution, e.g.:

List<CacheCluster> cacheClusters = clusterResult.getCacheClusters();
for (CacheCluster cacheCluster : cacheClusters) {
    List<CacheNode> cacheNodes = cacheCluster.getCacheNodes();

    System.out.println("List size: " + cacheNodes.size());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top