Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Elasticache Redis cluster - Can't get Endpoint

I need to get the endpoint for a Redis cluster in Amazon Elasticache. The following code works for a Memcached cluster, but not for a Redis:

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;

import com.amazonaws.services.elasticache.AmazonElastiCacheClient;
import com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest;
import com.amazonaws.services.elasticache.model.DescribeCacheClustersResult;
import com.amazonaws.services.elasticache.model.CacheNode;
import com.amazonaws.services.elasticache.model.CacheCluster;
import com.amazonaws.services.elasticache.model.Endpoint;

public class Redis {
    public static void main(String[] args) {
        AWSCredentials credentials = 
            new ProfileCredentialsProvider("default").getCredentials();
        AmazonElastiCacheClient amazonClient = new AmazonElastiCacheClient(credentials);
        amazonClient.setRegion(Regions.EU_WEST_1);
        DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest();
        dccRequest.setShowCacheNodeInfo(true);
        dccRequest.withCacheClusterId("app-001");
        DescribeCacheClustersResult clusterResult = 
            amazonClient.describeCacheClusters(dccRequest);

        CacheCluster cacheCluster = clusterResult.getCacheClusters().get(0);
        System.out.println("cluster: " + cacheCluster);
        System.out.println("endpoint: " + cacheCluster.getConfigurationEndpoint());
    }
}

The output is:

cluster: {CacheClusterId: app-001,ClientDownloadLandingPage: https://console.aws.amazon.com/elasticache/home#client-download:,CacheNodeType: cache.r3.large,Engine: redis,EngineVersion: 2.8.19,CacheClusterStatus: available,NumCacheNodes: 1,PreferredAvailabilityZone: eu-west-1a,CacheClusterCreateTime: Thu May 21 11:43:03 CEST 2015,PreferredMaintenanceWindow: mon:04:00-mon:05:00,PendingModifiedValues: {CacheNodeIdsToRemove: [],},CacheSecurityGroups: [],CacheParameterGroup: {CacheParameterGroupName: default.redis2.8,ParameterApplyStatus: in-sync,CacheNodeIdsToReboot: []},CacheSubnetGroupName: default,CacheNodes: [{CacheNodeId: 0001,CacheNodeStatus: available,CacheNodeCreateTime: Thu May 21 11:43:03 CEST 2015,Endpoint: {Address: app-001.3pusxn.0001.euw1.cache.amazonaws.com,Port: 6379},ParameterGroupStatus: in-sync,CustomerAvailabilityZone: eu-west-1a}],AutoMinorVersionUpgrade: true,SecurityGroups: [{SecurityGroupId: sg-3231f657,Status: active}],ReplicationGroupId: app,SnapshotRetentionLimit: 0,SnapshotWindow: 22:00-23:00}
endpoint: null

Note how the cluster object contains the endpoint information (key: Endpoint), but nevertheless getConfigurationEndpoint returns null.

How do I get the endpoint?

like image 546
tokland Avatar asked May 21 '15 11:05

tokland


People also ask

How do I get Redis endpoint?

To find a Redis (cluster mode enabled) cluster's endpointFrom the navigation pane, choose Redis clusters. The clusters screen will appear with a list of Redis (cluster mode disabled) and Redis (cluster mode enabled) clusters. Choose the Redis (cluster mode enabled) cluster you wish to connect to.

How do you draw an endpoint in ElastiCache?

Sign in to the AWS Management Console and open the ElastiCache console at https://console.aws.amazon.com/elasticache/ . From the navigation pane, choose Memcached clusters. The cache clusters screen will appear with a list of Memcached clusters. Find the Memcached cluster you want the endpoints for.

What is configuration endpoint in Redis?

Redis (Cluster Mode Enabled) endpoints A Redis (cluster mode enabled) cluster has a single configuration endpoint. By connecting to the configuration endpoint, your application is able to discover the primary and read endpoints for each shard in the cluster. For more information, see Finding connection endpoints.

What is Redis reader endpoint?

A reader endpoint will split incoming connections to the endpoint between all read replicas in a Redis cluster. Reader endpoints keep up with cluster changes in real-time as replicas are added or removed.


1 Answers

As it usually happens, I found the solution right after posting the question. In Redis you have to access the cache nodes:

Endpoint endpoint = cacheCluster.getCacheNodes().get(0).getEndpoint();
like image 153
tokland Avatar answered Sep 27 '22 15:09

tokland