DEV Community

Deepak Poudel
Deepak Poudel

Posted on

Complete guide to protect Amazon EBS Snapshots from accidental deletion using AWS Recycle Bin

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
In the volumes section, we can see a list of existing EBS volumes.

Image description
Select the EBS volume using the checkbox on the left side of the volume name.
Image description
Now, we need to create an EBS snapshot for the volume above. For that, click on “Action” and then “Create snapshot.”.

Image description
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
A message is shown after the successful creation of a snapshot with its unique ID.

Image description
Step2: Configuration of Recycle Bin
Search for Recycle Bin in the search bar and select that service.
Image description
In the recycle bin, we must create a retention rule to protect the snapshot. Click on “Click retention rule.”

Image description

Image description
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
After configuring all the details, click on “Create retention rule” at the bottom.

Image description
The retention rule that we configured can be seen in the home section of the recycle bin.

Image description
The retention rule has one feature for rule lock. Select the rule and click on "Action,” then “Edit retention rule lock.”

Image description
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
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
Select the snapshot and click on "Actions,” then “Delete snapshot.”

Image description
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
Select “Resources” just below the recycle bin on the left side.

Image description

Image description
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
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
Navigate to the EBS snapshot section where, we can see the recovered snapshot.

Image description
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).

Top comments (0)