Working with AWS Cloud from CommandLine — Part4
In this article, we will understand how to create Snapshots in aws cloud using aws cli.
In previous part, we learnt how to store data permanently in ec2 instance. For this we created and attached an external EBS volume to the ec2 instance.
But, as discussed in the previous part, an EBS volume created in one availability zone is available only within that availability zone.
In this article we will learn how to attach an EBS Volume which is present in availability zone or region other then the instance. To solve this use case, we will be learning about Snapshots.
Lets get started!
Lets start with a situation, suppose, we have two instances launched in two different regions say Mumbai(ap-south-1) in the availability zone (ap-south-1a) and Singapore(ap-southeast-1) in the availability zone(ap-southeast-1b).
Instance launched in Mumbai Region(ap-south-1):
Instance launched in Singapore region(ap-southeast-1):
To this instance we have attached an EBS volume which was created in the same availability zone(ap-southeast-1b) in the same region Singapore.
I have created a partition named as /dev/xvdf1 in the volume /dev/xvdf that i have attached to the instance running in Singapore,
and mounted this partition to a directory called /Volume-Singapore.
In this directory, i have created a file named as test-singapore-file.txt.
Our goal is to detach this volume from this instance present in the region Singapore and attach it to the instance present in region Mumbai. For this we will use the concept of snapshots.
An EBS snapshot is a point-in-time copy of your Amazon EBS volume, which is lazily copied to Amazon Simple Storage Service (Amazon S3). EBS snapshots are incremental copies of data. This means that only unique blocks of EBS volume data that have changed since the last EBS snapshot are stored in the next EBS snapshot. This is how incremental copies of data are created in Amazon AWS EBS Snapshot.
The main use of Snapshots is for backups, but it can also be utilise for such use case.
Step 1: Detaching the volume from the instance.
To safely detach a volume from a system, it is a good practice to first unmount its partitions.
Step 1.a: To unmount a partition:
Command: sudo umount <partition_name>
The volume only contained a single partition named as /dev/xvdf1.
We can observe that, after unmounting the partition from the directory, Volume-Singapore doesnt contains the file, which we created for testing. Actually. this file is stored in the drive, and we will see the same file when we will connect this drive to the other instance running in Mumbai region.
Step 1.b To Detach a Volume from an instance.
Since, the default region is different in my system’s aws cli, therefore, i have to explicitly specify the region to detach the volume present in Singapore.
Command: aws ec2 detach-volume --volume-id=<> --instance-id=<>
Step 2: Creating the snapshot from the detached volume.
To create a snapshot.
Command: aws ec2 create-snapshot --volume-id=<> --description="any_description" --region=ap-southeast-1
To create a volume using this snapshot in Mumbai region, we first have to copy the snapshot to Mumbai region.
Step 3: To copy the snapshot to Mumbai region.
Command: aws ec2 copy-snapshot source-snapshot-id=<>
Source region is the region where snapshot is actually present, which is in this case is Singapore(ap-southeast-1) and destination region is the region, where we have to copy and move this snapshot to, which is Mumbai region(ap-south-1).
Step 4: To create an EBS volume using this snapshot(present in Mumbai region).
Note: While creating an EBS volume from this snapshot, we have to specify the availabilty zone in which we want to create the volume in.
Since, we know that an EBS volume is available only within the same availability zone, in which it is created in, therefore, to attach this volume to the instance present in availability zone: ap-south-1a, we must create the volume in the same availabilty zone.
Step 5: Attach this volume to the instance(ap-south-1a).
Command: aws ec2 attach-volume --volume-id=<> --instance-id=<>
We can see that the volume status has changed from available to attached.
From the previous article, we already know that, once the partitioning is done, we dont require to create partitions again, at the time of connecting the volume to the instance. We only need to mount it.
In this case, I have created a directory called /Volume-Mumbai and have mounted the partitition /dev/xvdf1, to this directory.
We can see that the data stored inside this drive in Singapore region is successfully transferred with complete drive to the Mumbai region.
And thats it. Done!
In the next part, we will learn about AWS Simple Storage Service (Amazon S3) and how to host a webpage using a webserver configured in an ec2-instance.
📝 ️Few Last Words
→ I will be sharing many article’s on Integrating multiple tools and technologies Cloud Computing, DevOps, Big Data Hadoop, Machine Learning etc. in Upcoming days .
→ Follow me on Medium for more Article’s on Research based and integration of new new tools and technologies .
For Furthur Queries, Suggestion’s Feel Free to Connect with me On Linkedin
Sunny Goswami - Graphic Era Deemed to be University - Dehradun, Uttarakhand, India | LinkedIn
View Sunny Goswami's profile on LinkedIn, the world's largest professional community. Sunny has 2 jobs listed on their…
For any doubt or query, let me know in the Response section!
If you like it then Clap & Share ..
Thankyou EveryOne For reading .!! | arigatou gozaimasu. sayonara!