Complete guide to protect Amazon EBS Snapshots from accidental deletion using AWS Recycle Bin
Published: 2024-03-12 06:58:37

Have you ever been wondering about or facing the problem of accidental deletion of Amazon EBS Snapshots and AMI?
Don’t worry; the AWS Recycle Bin is the solution to such a problem.
Normally, we use EBS snapshots to back up the data on our Amazon EBS volumes. The snapshots are very useful, mainly in disaster recovery, data migration, and backup compliance. But in some cases, those snapshots can be accidentally deleted, which can cause a huge loss of data. For that reason, in this blog, I will be guiding you to use Amazon Recycle Bin.
Let’s get started from the very beginning.
Pre-requisite: Before starting the steps to configure the recycle bin, we must have at least one EBS volume. That EBS volume can be independent of EC2 or attached to an EC2 instance.
Steps
Step1:  Configuration of EBS snapshot
First of all, let us create an EBS snapshot from the EBS volume. Navigate to the EC2 service. In the left navbar, click on "Volumes.”. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u43gumb3b1bteazqx5fs.png)
In the volumes section, we can see a list of existing EBS volumes.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bggsl5u39z5c4281p4qu.png)
Select the EBS volume using the checkbox on the left side of the volume name.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekqa7nie4zck4uyvzk1d.png)
Now, we need to create an EBS snapshot for the volume above. For that, click on “Action” and then “Create snapshot.”. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddw8mnhpobgib69s38b1.png)
Provide the details for the EBS snapshot by filling out the Description and Tags section. Multiple tags can also be provided as per requirement. We will be using the tag while configuring the recycle bin. After that, create the EBS snapshot.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8bfk0fd3ye8wbtqjbfz.png)
A message is shown after the successful creation of a snapshot with its unique ID.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8flagc5d38ocez617v5z.png)
Step2: Configuration of Recycle Bin
Search for Recycle Bin in the search bar and select that service.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q0l939fpid0vh3n6b8p4.png)
In the recycle bin, we must create a retention rule to protect the snapshot. Click on “Click retention rule.”

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktwq0powyl7fthzi956y.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkxgc5l5jt5qe073expw.png)
In the rule details, provide the retention rule name so that we can identify the rule properly. Also, provide a relevant description of the rule.
In the resource type, select EBS Snapshots. To apply the retention rule to all EBS snapshots, select “Apply to all resources.”.  In this blog, I will be applying the retention rule to only one snapshot. Select the relevant tags for the snapshots, which we have to retain, and click on "Add.”. In the retention period, we can choose the time period for which the resources can be recovered after deletion.The minimum time can be 1 day, and the maximum can be 365 days.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqiusjxflvl1a185003w.png)
After configuring all the details, click on “Create retention rule” at the bottom. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmwp56tgnflw0242los3.png)
The retention rule that we configured can be seen in the home section of the recycle bin.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d3pvxnky33klshe37en.png)
The retention rule has one feature for rule lock. Select the rule and click on "Action,” then “Edit retention rule lock.”

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edm4xq0ymwtzp655qn3p.png)
In the rule lock setting, we can configure it to prevent the retention rule itself from being accidentally or maliciously updated or deleted. There are two options: “unlock” and “lock.”. If we select Unlock, the rule can be modified and deleted. But if we select lock, then the rule can’t be modified or deleted until it is unlocked and the specified delay period has expired.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gymw1mw2dak8trrbt5zl.png)
Step3: Checking the retention 
Now, we need to test the use of the recycle bin by deleting the snapshot. Navigate to the EBS snapshots section by searching “snapshots” in the search bar.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mxtma5tf0ha28lici5u.png)
Select the snapshot and click on "Actions,” then “Delete snapshot.”


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikkwyfhbeofhtl95iub6.png)
After successfully deleting the snapshot, we can see that the snapshot no longer exists. This deletion can be done accidentally in some cases.  Click on “Recycle Bin” in the top right. This will redirect to the Recycle Bin service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bj8iyyp9lf8jmxw5zw0.png)
Select “Resources” just below the recycle bin on the left side.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8i8b904pqws9fsapv1ot.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfaz90x5jzyu4fgzydeq.png)
In the resources section we can see the EBS snapshot that we deleted earlier. It also shows the bin entry date and bin exit date. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wt749pkmxfpeloa4tovn.png)
To recover the snapshot, select the snapshot and click on “Recover” in the top right section. 
Now, click “Recover resources” to retain the snapshot volume


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jeb4gbjrdnyd6ydbfnx.png)
Navigate to the EBS snapshot section where, we can see the recovered snapshot.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eaw6upfe2p2qg0wlfnbv.png)
In this way we have successfully used Recycle Bin to recover EBS snapshot from accidental deletion. In the similar manner it can also be used to recover Amazon Machine Image (AMI).