Finding AWS ElastiCache endpoints with Java


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:

When I run it, I get the following output:

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?


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:

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

Leave a Reply