At the below link:
http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/ClientConfig.ReplicationGroup.html
following content is present:
REPLICATIONGROUP my-repgroup My replication group available
CLUSTERID my-redis-primary
CLUSTERID my-replica-1
NODEGROUP 0001 my-repgroup.f310xz.ng.0001.cache.amazonaws.com 6379 available
NODEGROUPMEMBER my-redis-primary 0001 my-redis-primary.f310xz.0001.cache.amazonaws.com 6379 us-west-2a primary
NODEGROUPMEMBER my-replica-1 0001 my-replica-1.f310xz.0001.cache.amazonaws.com 6379 us-west-2b replica
Connecting to Clusters in a Replication Group (ElastiCache API)
In the above, to the extreme right
There is 'primary' and 'replica'
as of today, in the aws console,
when i give the 'describe-replication-groups' command
i don't see the 'primary' and 'replica'
instead i see something like below:
"NodeGroupMembers": [
{
"PreferredAvailabilityZone": "us-west-2b",
"CacheNodeId": "0001",
"CacheClusterId": "ec-redis-cluster1-0001-001"
},
{
"PreferredAvailabilityZone": "us-west-2b",
"CacheNodeId": "0001",
"CacheClusterId": "ec-redis-cluster1-0001-002"
},
{
"PreferredAvailabilityZone": "us-west-2b",
"CacheNodeId": "0001",
"CacheClusterId": "ec-redis-cluster1-0001-003"
}
]
i tried various commands, could not find.
in what way, can i see the details of if some shard/node is primary/replica
thanks in advance
echo "cluster nodes" | redis-cli -c -h redis-cluster | grep master
AWS Elasticache Redis setup when created as a multi node setup has 2 modes - cluster mode enabled and disabled as described here. This is important to the question at hand.
If your Elasticache cluster is in cluster mode disabled then doing
aws elasticache describe-elasticache-replication-groups --replication-group-id test-1
will show output similar to this:
{
"CurrentRole": "replica",
"PreferredAvailabilityZone": "us-west-1c",
"CacheNodeId": "0001",
"ReadEndpoint": {
"Port": 6379,
"Address": "xxxx"
},
"CacheClusterId": "xxxx"
},
{
"CurrentRole": "primary",
"PreferredAvailabilityZone": "us-west-1c",
"CacheNodeId": "0001",
"ReadEndpoint": {
"Port": 6379,
"Address": "xxxx"
},
"CacheClusterId": "xxxx"
}
which helps you determine the target node's primary or replica role. The key CurrentRole is not available in AWS Elasticache cluster mode enabled where doing
aws elasticache describe-elasticache-replication-groups --replication-group-id test-2
will show output similar to:
{
"PreferredAvailabilityZone": "us-west-1c",
"CacheNodeId": "0001",
"CacheClusterId": "xxxxx"
},
{
"PreferredAvailabilityZone": "us-west-1c",
"CacheNodeId": "0001",
"CacheClusterId": "xxxxxxx"
},
The above output doesn't have CurrentRole or any other corresponding key that gives insight into the node's role. In this case you have 2 options:
If you have access to port 6379 of the AWS Elasticache Redis cluster - get the master/slave info by following the previous answer by Abhishek.
If you don't have access to the cluster i.e. if you are writing an AWS Lambda or some code that is not running on the machine which can't access port 6379 of the cluster, the roundabout way is to check the IsMaster metric for each node of each shard:
aws cloudwatch get-metric-data --cli-input-json file://test.json
where test.json looks like so:
{
"MetricDataQueries": [
{
"Id": "is_master_test",
"MetricStat": {
"Metric": {
"Namespace": "AWS/ElastiCache",
"MetricName": "IsMaster",
"Dimensions": [
{
"Name": "CacheClusterId",
"Value": "xxxxx"
},
{
"Name": "CacheNodeId",
"Value": "0001"
}
]
},
"Period": 60,
"Stat": "Minimum",
"Unit": "Count"
},
"Label": "is_master_test",
"ReturnData": true
}
],
"StartTime": "2019-06-12T10:08:0000",
"EndTime": "2019-06-12T10:09:0000"
}
If the target node is the master the output will be like so:
{
"MetricDataResults": [
{
"Timestamps": [
"2019-06-12T10:05:00Z"
],
"StatusCode": "Complete",
"Values": [
1.0
],
"Id": "is_master_test",
"Label": "is_master_test"
}
]
}
If the target node isn't the master the output will be like so:
{
"MetricDataResults": [
{
"Timestamps": [
"2019-06-12T10:05:00Z"
],
"StatusCode": "Complete",
"Values": [
0.0
],
"Id": "is_master_test",
"Label": "is_master_test"
}
]
}
Please note that I am using the metric "Minimum" to check if this node stayed as the Master for at least the last 1 minute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With