Recycle Bin - AWS EBS Snapshot recovery feature

ยท

4 min read

Recycle Bin is a data recovery feature that enables you to restore accidentally deleted Amazon EBS snapshots and EBS-backed AMIs. When using Recycle Bin, if your resources are deleted, they are retained in the Recycle Bin for a time period that you specify before being permanently deleted.

You can restore a resource from the Recycle Bin at any time before its retention period expires. After you restore a resource from the Recycle Bin, the resource is removed from the Recycle Bin and you can use it in the same way that you use any other resource of that type in your account.

Using Recycle Bin helps to ensure business continuity by protecting your business-critical data against accidental deletion.

Here's an overview of the "Recycle Bin" feature for Amazon EBS Snapshots:

  1. Functionality: With the introduction of the Recycle Bin feature, when you delete an EBS snapshot, instead of being removed immediately, the snapshot is moved to the Recycle Bin. This means the snapshot is in a "soft deleted" state and can be recovered.

  2. Retention Period: Snapshots in the Recycle Bin have a retention period, that you specify. During this time, you can recover the snapshot. After the retention period expires, the snapshot is permanently deleted.

  3. Costs: Resources in the Recycle Bin are billed at their standard rates. There are no additional charges for using Recycle Bin and retention rules. For more information, see Amazon EBS pricing. Hence, if you're sure about not needing a snapshot, it's advisable to remove it from the Recycle Bin to avoid unnecessary costs.

  4. Visibility: Snapshots in the Recycle Bin are not visible in the regular EBS Snapshots console view, ensuring that the user experience remains uncluttered. There's a separate view or filter to see the snapshots in the Recycle Bin.

  5. Recovery: If you realize you've mistakenly deleted a snapshot, you can go to the Recycle Bin view, select the snapshot, and choose to recover it. Once recovered, it goes back to its regular state, and you can use it as you would with any other snapshot.

  6. Permanent Deletion: If you're certain that you no longer need a snapshot, you can bypass the retention period by permanently deleting it from the Recycle Bin.

This feature essentially provides a safety net against unintentional deletions, giving AWS users a grace period to realize and rectify potential mistakes. Always remember to review the contents of the Recycle Bin periodically and remove unwanted snapshots to manage costs effectively.

Tutorial: Create a Recycle Bin retention rule

Here's a step-by-step guide on how to create a Recycle Bin retention rule for EBS snapshots and how to recover an EBS snapshot from the Recycle Bin using the AWS Command Line Interface (CLI):

Prerequisites:

  • Ensure that the AWS CLI is installed and configured with the necessary access rights.

  • You need permission to manage EBS snapshots and modify data lifecycle policies.

๐Ÿ’ก
To run the EC2 instance with the EBS volume attached follow this guide: How to launch a single EC2 instance via AWS CLI

1. Create a Recycle Bin Retention Rule:

  1. Use the create-rule AWS CLI command to create retention rule:

     aws rbin create-rule \
     --retention-period RetentionPeriodValue=number_of_days,RetentionPeriodUnit=DAYS \
     --resource-type EBS_SNAPSHOT|EC2_IMAGE \
     --description "rule_description" \
     --lock-configuration 'UnlockDelay={UnlockDelayUnit=DAYS,UnlockDelayValue=unlock_delay_in_days}' \
     --resource-tags ResourceTagKey=tag_key,ResourceTagValue=tag_value
    

    For --retention-period, specify the number of days to retain deleted snapshots in the Recycle Bin. For --resource-type, specify EBS_SNAPSHOT for snapshots or EC2_IMAGE for AMIs. To create a tag-level retention rule, for --resource-tags, specify the tags to use to identify the snapshots that are to be retained. To create a Region-level retention rule, omit --resource-tags. To lock a retention rule, include --lock-configuration, and specify the unlock delay period in days.

2. View Recycle Bin retention rules:

  1. Use the list-rules AWS CLI command, and for --resource-type, specify EBS_SNAPSHOT for snapshots or EC2_IMAGE for AMIs:

     aws rbin list-rules --resource-type EBS_SNAPSHOT|EC2_IMAGE
    
  2. The following example command provides lists all retention rules that retain snapshots.

     aws rbin list-rules --resource-type EBS_SNAPSHOT
    
  3. To view information for a specific retention rule use the get-rule AWS CLI command:
aws rbin get-rule --identifier rule_ID

3. Delete Recycle Bin retention rules:

  1. Use the delete-rule AWS CLI command. For --identifier, specify the ID of the retention rule to delete.

     aws rbin delete-rule --identifier rule_ID
    
  2. The following example command deletes retention rule 6lsJ2Fa9nh9:

     aws rbin delete-rule --identifier 6lsJ2Fa9nh9
    

For more information on retention rule AWS CLI commands refer to Work with retention rules.

References:

  1. Recycle Bin

  2. Work with retention rules

  3. New โ€“ Recycle Bin for EBS Snapshots

ย