1

I'm trying to describe my cache cluster nodes in AWS Elasticache. I am using the example from Finding AWS ElastiCache endpoints with Java (the solution code).

I use the code:

 DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest();    
    dccRequest.setShowCacheNodeInfo(true);

    elasticache.setEndpoint("ec2.us-west-1.amazonaws.com");
    DescribeCacheClustersResult clusterResult = elasticache.describeCacheClusters(dccRequest);
    System.out.println("cache cluster node fleet size: " + clusterResult.getCacheClusters().size());
    for (CacheCluster cacheCluster : clusterResult.getCacheClusters()) {
        List<CacheNode> cacheNodes = cacheCluster.getCacheNodes();

        System.out.println("cache cluster size: " + cacheNodes.size());
    }

When I run this code I get the error:

Exception in thread "main" Status Code: 400, AWS Service: AmazonElastiCache, AWS Request ID: null, AWS Error Code: null, AWS Error Message: null

If I remove the setEndpoint code, the code doesn't error out, but no nodes are returned and printed. The reason I am guessing is because the US-EAST region is queried by default.

Does anyone know how I can circumvent this error?

Community
  • 1
  • 1
Atma
  • 29,141
  • 56
  • 198
  • 299

1 Answers1

2

Your problem is that you are setting the endpoint to the EC2 endpoint not the Amazon ElastiCache endpoint. The corrected code snippet is:

elasticache.setEndpoint("elasticache.us-west-1.amazonaws.com");

You can find a complete list of endpoints in this document

Wade Matveyenko
  • 4,290
  • 1
  • 23
  • 27