Amazon Elastic Block Store (EBS) Volumes are highly available and reliable storage volumes that can be attached to any running EC2 instance that is in the same Availability Zone. When we attach the EBS volumes to EC2 instances they act as physical drive disks that we can format and use to install our operating system, our files and so on.
EBS Snapshot is one of the most useful tools offered by Amazon to make a copy of your volume. There are several reasons to do snapshots:
Amazon is providing various interfaces to create a snapshot of a Volume like Amazon AWS console, Command-line, APIs and SDKs. From AWS Console, you can create snapshots for any volume from either Volumes tab or from the Snapshots tab.
Unfortunately, AWS doesn’t have the scheduling feature with already set times like daily, hourly, weekly and etc.
You need to automate snapshots of volumes by yourself, using either command-line or APIs or SDKs. Here I am showing a script where you can automate the snapshot operations of volumes on regular intervals using AWS command-line tools.
This script needs mainly 3 parameters:
Let’s see how it works:
aws ec2 create-snapshot –volume-id $VOL_ID –description “$DESCRIPTION” –region $REGION &>> $SNAP_CREATION
aws ec2 describe-snapshots –query Snapshots[*].[SnapshotId,VolumeId,Description,StartTime] –output text –filters “Name=status,Values=completed” “Name=volume-id,Values=$VOL_ID” | grep -v “CreateImage” > $SNAPSHOT_INFO
aws ec2 delete-snapshot –snapshot-id $SNAP_ID –region $REGION –output text
Here is the complete script (Evernote) and sample volume-list file for your reference.
When you take the snapshots of your volumes, it would be a good idea to ignore the Auto Scaling instances volumes, because those instances are stateless. Remember that auto-scaling machines will have an AMI to store their required config and data.
The sample script is to give you an idea of we can do the snapshots management, but you can always extend it to meet your needs.
It's Flash Sale time! Get 50% off your first year with Cloud Academy: all access to AWS, Azure, and Cloud…
In this blog post, we're going to answer some questions you might have about the new AWS Certified Data Engineer…
This is my 3rd and final post of this series ‘Navigating the Vocabulary of Gen AI’. If you would like…