# Delete Idle ElastiCache/Memcached Cluster

## What It Does

Deletes idle Amazon ElastiCache clusters—Memcached, serverless, or provisioned—that are not actively used. Idle cache clusters often result in unnecessary compute and memory expenses. Removing them helps reduce cost without impacting active workloads.

## Risk and Scope

| Detail                   | Value              |
| ------------------------ | ------------------ |
| **Risk Level**           | Medium             |
| **AWS Service Targeted** | Amazon ElastiCache |

{% hint style="warning" %}

## Permissions Required

**Delete Permissions**

* `elasticache:DeleteCacheCluster`
* `elasticache:DeleteReplicationGroup`
* `elasticache:DeleteServerlessCache`

**Read Permissions**

* `elasticache:DescribeCacheClusters`
* `elasticache:DescribeReplicationGroups`
* `elasticache:DescribeServerlessCaches`

> These permissions are granted **only to the runbook**, not to the OneLens platform itself.
> {% endhint %}

## Optimization Policies Addressed

This runbook remediates violation tickets of the following policy:

| Policy ID | Policy Name                                           |
| --------- | ----------------------------------------------------- |
| elc\_101  | Idle ElastiCache Memcached clusters should be deleted |

## Risk Mitigation

{% hint style="success" %}

## Risk Mitigation Strategy

* The change is assessed as **low risk** with limited scope and impact.
* **No downtime** is expected during or after implementation.
* **No additional safety measures** are required due to the non-disruptive nature of the change.
* A **rollback plan is not defined**, as standard procedures are sufficient to manage the change.
  {% endhint %}

## How to Install

Refer to the [Runbook Setup Guide ](/automate/remediations/runbooks/install-runbooks.md#installing-a-runbook)for steps to install and enable this runbook in your environment.

## Runbook Workflow

### Step 1: Start

**Trigger:** Begins the runbook to identify and delete idle ElastiCache clusters.

### Step 2: CheckForCacheType

**Action:** Runs a script to determine the type of ElastiCache (Memcached, serverless, or provisioned) for each idle cluster.

### Step 3: If/Else

**Condition:** Checks if any ElastiCache cluster is eligible for deletion.

1. **If all are in manual and available state:**&#x20;
   1. **DeleteMemcached**\
      Executes `DeleteCacheCluster` for idle Memcached clusters.
   2. **DeleteServerlessCache**\
      Executes `DeleteServerlessCache` for idle serverless clusters.
   3. **DeleteProvisioned**\
      Executes `DeleteReplicationGroup` for idle provisioned Redis clusters.
   4. **RunScript**\
      Raises a runtime error to capture error, failing the workflow explicitly.
2. **Else:**

   Workflow terminates if no deletable cluster is found.

## See How It Works

<figure><img src="/files/hj1NQ6GpU5cvW6ZiV2pn" alt=""><figcaption></figcaption></figure>

## Triggering the Runbook

To run this workflow:

### **1. Locate the Ticket**

Identify the ticket associated with the above mentioned policy violation.

### **2. Execute the Runbook**

Follow the steps described in the [executing a runbook](/automate/remediations/runbooks.md#executing-a-runbook) section to apply this runbook to the ticket.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onelens.cloud/automate/remediations/runbooks/runbook-catalog/delete-idle-elasticache-memcached-cluster.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
