Finding AWS ElastiCache endpoints with Java

前端 未结 1 954
不知归路
不知归路 2021-01-05 13:57

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

相关标签:
1条回答
  • 2021-01-05 14:10

    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());
    }
    
    0 讨论(0)
提交回复
热议问题