# Delete EBS Snapshots for which corresponding volumes are not in use

## What It Does

Deletes Amazon EBS snapshots whose corresponding volumes are no longer in use. These orphaned snapshots can consume unnecessary storage costs.

{% hint style="success" %}

## Recommendation&#x20;

If you **require snapshots but are accessed infrequently**, consider archiving them for up to **75% savings**.&#x20;

However, archived snapshots incur a **minimum 90-day charge,** and restoring them may **take up to 72 hours**.
{% endhint %}

## Risk and Scope

| Detail                   | Value      |
| ------------------------ | ---------- |
| **Risk Level**           | Low        |
| **AWS Service Targeted** | Amazon EBS |

{% hint style="warning" %}

## Permissions Required

**Delete Permission**

* `ec2:DeleteSnapshot`

**Read Permission**

* `ec2:DescribeSnapshots`

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

## Optimization Policies Addressed

This runbook to remediate violation tickets triggered by of the following policy:

| Policy ID | Policy Name                                               |
| --------- | --------------------------------------------------------- |
| ebs\_100  | EBS Snapshots of the deleted volumes should be deleted    |
| ebs\_101  | EBS Snapshots of unattached EBS volumes should be deleted |
| ebs\_102  | EBS Snapshots created while copying AMI 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 remove orphaned EBS snapshots.

### Step 2: DescribeSnapshots

**Action:** Calls `DescribeSnapshots` to retrieve all EBS snapshots.

### Step 3: If/Else

**Condition:** Checks if any snapshots exist for which the associated EBS volumes no longer exist.

1. **BranchOnValidSnapshot**

   Verifies if each snapshot state is completed.

   1. **DeleteSnapshot**\
      Executes `DeleteSnapshot` for snapshots that qualify for deletion.
   2. **RunScript**

      Raises a runtime error to capture errors, failing the workflow explicitly.
2. **Else:**

   The workflow ends if no qualifying snapshots are found.

## See How it Works

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

## Triggering the Runbook

To run this runbook:

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

Find the ticket generated by the **above 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-ebs-snapshots-for-which-corresponding-volumes-are-not-in-use.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.
