Once upon a time there exist an ElastiCache Redis cluster that I no longer needed. I know that the cluster could be deleted via ElastiCache web console. However, as a command-line addict as myself, I wanted to use AWS CLI to delete the cluster instead.
Well, actually this is my first time trying to delete an ElastiCache cluster using the CLI. I’m going to try to document how I do this, and what mistakes I’d make a long the way. The cluster name is called ‘my-test-cluster’. Let’s get started
First, verify if the cluster exists by using the describe-cache-clusters
subcommand:
➜ aws elasticache describe-cache-clusters \
--query "CacheClusters[].{CacheClusterId:CacheClusterId}"
[
{
"CacheClusterId": "my-tests-cluster-0001-001"
},
{
"CacheClusterId": "my-tests-cluster-0001-002"
}
]
The cluster contains 2 nodes. Let’s see if we can delete it by supplying one of the node’s Id:
➜ aws elasticache delete-cache-cluster \
--cache-cluster-id my-tests-cluster-0001-001
An error occurred (InvalidParameterCombination) when calling the DeleteCacheCluster
operation: Cannot delete cache cluster with cluster mode enabled.
Nope, it doesn’t like it. What should I do? Or, what would you do? Well, google! According to this [1], I should “delete_replication_group” instead.
Deletes an existing replication group. By default, this operation deletes the entire replication group, including the primary/primaries and all of the read replicas. If the replication group has only one primary, you can optionally delete only the read replicas, while retaining the primary by setting RetainPrimaryCluster=true .
Trying to find the replication Id. (I should have guessed the replication Id is the cluster Id.)
➜ aws elasticache describe-cache-clusters | grep -i replication
"ReplicationGroupId": "my-tests-cluster",
"ReplicationGroupLogDeliveryEnabled": false,
"ReplicationGroupId": "my-tests-cluster",
"ReplicationGroupLogDeliveryEnabled": false,
➜ aws elasticache describe-cache-clusters \
--query "CacheClusters[].{ReplicationGroupId:ReplicationGroupId}"
[
{
"ReplicationGroupId": "my-tests-cluster"
},
{
"ReplicationGroupId": "my-tests-cluster"
}
]
Well, now that we the replication Id, we can delete it with the following command:
➜ aws elasticache delete-replication-group --replication-group-id my-tests-cluster
{
"ReplicationGroup": {
"ReplicationGroupId": "my-tests-cluster",
"Description": "Easy created dev cluster on 2024-07-02T00:58:53.066Z",
"GlobalReplicationGroupInfo": {},
"Status": "deleting",
"PendingModifiedValues": {},
"AutomaticFailover": "enabled",
"MultiAZ": "enabled",
"SnapshotRetentionLimit": 1,
"SnapshotWindow": "18:00-19:00",
"TransitEncryptionEnabled": true,
"AtRestEncryptionEnabled": true,
"ARN": "arn:aws:elasticache:ap-southeast-2:144666666666:replicationgroup:my-tests-cluster",
"LogDeliveryConfigurations": [],
"ReplicationGroupCreateTime": "2024-07-02T00:59:10.470000+00:00",
"DataTiering": "disabled",
"AutoMinorVersionUpgrade": true,
"NetworkType": "ipv4",
"IpDiscovery": "ipv4",
"TransitEncryptionMode": "required",
"ClusterMode": "enabled"
}
}
Finally, verify that I should have no cluster left on my account:
➜ aws elasticache describe-cache-clusters
{
"CacheClusters": []
}
Reference: