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 Cac
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!
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());
}