> For the complete documentation index, see [llms.txt](https://docs.onelens.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onelens.cloud/automate/remediations/remediations-runbooks/runbook-catalog/delete-idle-elasticache-memcached-cluster.md).

# 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/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:**
   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="https://3963693991-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiyNGpqVYfmDF6qt7Lzar%2Fuploads%2FnVm5OTrVUlwi1IDkv76U%2FScreenshot%202025-05-13%20at%2011.02.59.png?alt=media&amp;token=a213e4fb-58f3-4089-bce0-a99f498a8238" 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/remediations-runbooks.md#executing-a-runbook) section to apply this runbook to the ticket.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
