Save Data in EBS Volume

This tutorial will guide you through create Amazon EBS (Elastic Block Store) volume, attach it to your running instance and save your data to Amazon EBS. Before that lets understand what is Amazon EBS volumes and what are the features it provides

Amazon Elastic Block Store (EBS) provides block level storage volumes for use with Amazon EC2 instances. We can imagine it as attaching an external hard drive to your system to store data. We can attach multiple EBS volumes to an instance, but one volume can be attached to single instance at a time. Data will be remain saved in the volume after your instance is terminated.

Some Features of Amazon EBS Volumes
·        Amazon EBS allows you to create storage volumes from 1 GB to 1 TB
·        Amazon EBS volumes placed in a specific availability zone can then be attached to instances in that same availability zone.
·        Each storage volume is automatically replicated within the same Availability Zone. This prevents data loss due to failure of any single hardware component.
·        Amazon EBS also provides the ability to create point-in-time snapshots of volumes, which persists to Amazon S3. These snapshots can be used as the starting point for new Amazon EBS volumes. Snapshot can be used to instantiate new volume
·        AWS also enables you to create new volumes from AWS hosted public data sets.
·        Amazon CloudWatch exposes performance metrics for EBS volumes, giving you insight into bandwidth, throughput, latency, and queue depth.

Let’s proceed to actual work, there are two ways of create / attach volumes:
1. By running commands from command prompt
2. By using AWS Console
In this tutorial we will use approach #1

Define following environment variable:
If you want to know how to get your private key and certificate please click here

1. Create EBS volume:
$ ec2-create-volume --size 100 --availability-zone us-east-1a
·        Size in GB
·        It will return id of created volume

2. Attach the volume to running instance:
$ ec2-attach-volume vol-6715f30c -i i-da3162b5 -d /dev/sdh
·        vol-6715f30c: Volume id
·        i-da1662b5: Instance id

3. Format the Volume, if first time attached to any instance (first time activity, if you do it again you will loose all your data):
$ yes | mkfs -t ext3 /dev/sdh

4. Mount Volume:
4.1 Create directory in which we will mount volume
$ mkdir /disk2

4.2 Mounts the volume to specified directory
$ mount /dev/sdh /disk2

Now volume is attaché to your instance, you can copy your data to / from volume

5. Unmount Volume:
$ umount -l /disk2/

6. Detach the Volume:
$ ec2-detach-volume  vol-6715f30c -i i-da3162b5
·        vol-6715f30c: Volume id
·        i-da3162b5: Instance id

7. Delete Volume:
$ ec2-delete-volume vol-6715f30c


No comments:

Post a Comment