Loading...
 

Setting up and accessing EBS and S3 storage

 

  • Volumes are like hard drives or flash drives.

  • Volumes are created as Elastic Block Storage (EBS) devices.

  • An instance should have at least one volume, where the operating system runs. This volume is usually called the root volume.

  • It is a good practise to have a separate volume for your data (like having an external drive that you can connect and disconnect to several different instances).

  • In tutorial we will create an additional volume and access it in our instance.

  • We will also create an S3 storage bucket and learn to access it

1. Create volume

From the EC2 console left hand menu bar, click “Volumes” under the “Elastic Block Storage” section. In the resulting volumes page, you might see other volumes (in the screenshot below, we see the 8 GB root volume). Click the “Create Volume” button to create a new volume.

rG9-0sEiedbYPLPVwfBf8TiqwPE6zsD74x8XhDsn4GiymkM34nHXD_383EW-qxP6csu3pU-Aa_Pl-47sp2FzfUshMOzoXKo25e1VPJxSA-NCu83qhm57rIJCCC6CYQKkR7cIuF-G


1.1. Configure Volume

In the Create Volume window, enter “1” for Size, choose the “us-west-2b” for Availability zone (as us-west-2b is where the instance is running). Click “Create Volume” and “Close” the next window.

0d6_gvohYGWsCFVrLTXKv0YnrJLiQ27i09JwK9tVopmW8ssK1q8vNpUfbTiLNMbeN4eiQnBo48jLfxjyC9FZZMbCUeG1CSOpNgZEZ2ku3dPr03IVfBVBCnhBG48W4pK2uOl77VuN

1.2. Volume state

In the screenshot below, our volume window show two volumes. The 8 GB root volume that has the “State” as “in-use” and the 1 GB volume that we just created, with the “State” as “available”.


To check what volumes are currently mounted/attached in our instance, run the command “lsblk” command your instance terminal;

cIjgPkOQVVSvxQpn7H8nhBbp5QRQJebuyoI0r58hF0R3UseJflSp0n-pPH4VasTCllyhwbf0x71PkxAcTWmang-ClHPp1yxWv173QJ7PyXA72YgAWFMK3qdKWo6mpf0Z5Gh-z63s

 

The above screenshot shows that there is only one volume/device (xvda) attached to the instance and it is mounted in the root (“/”), with 8G size.

1.3. Attach volume

Click and select the new 1 GB volume that we just created.

Click “Actions” and “Attach Volume”.

3Stsqb58YFKKZsgSSWXAGLqvD1XZVkUmodpQezDnoUpg5F6ghc29ukDRu7NrysWLFs0wbjBvDUpk4noXUvsfq55qQSzdgIKuDkdMFznHdjFXutHl23fOjyiAu72A9zCirHEZaVL4


In the “Attach Volume” window, click the box next to “Instance” option and select the appropriate instance from the popup list. In our below example, we have one instance that is “running”, select this instance and click “Attach” button.

2lmED8YQlyAmArSG_fsi78TqH1SQYkgy00gfvTewuVIJSKvzfNWP5rBP2cpzM6LMUTifpG_Md1i6AxaqLRUNpU0npwH3OpVNh7nGnQSE2k1Gpj-IPAbB8NHDb7AmthS62yuZZmCo


Now if you run the “lsblk” command, you will see the new volume/device showing up in our instance, as xvdf, but not mounted yet.

fS1QjbZ7Zk-REJXDpgta21oglKHLlnEz2cClLbEIkxxa9gGlmKzYy1bX1UCuq7rw6be1XK3cr_jbXJubz1QYF3QvsAWFs6lVrSCQJWddP0Yb2HksA-UpzSs7y1Un5D3GSXJwjm9J


1.4. Formatting the volume

Formatting the new volume has to be done only once. After that you can attach/mount detach/unmount the new volume as you would do with a regular physical external flash drive or hard drive. As the new device is attached as xvdf, run the following command to format it;

sudo mkfs -t ext4 /dev/xvdf

fzgayaMH_yr51rOAW2GN4sWi4pOmGiPYTjAPtBa6zJdFpyd023hRLmiE2BVqtBtja685yvKsZK7yIHvC6D3Bf1-yxu1hCMOyzCMCWtcJ1hXAIZT3zcK3BZAFzf3dyJ4sxQWPbwH2

 

1.5. Mounting the new volume

Now that we have formatted the new volume, we need a place to mount it.

Create a new directory in your home directory, using the following command;

mkdir data

8Um0wj29m1kotydDADzA7GdCrgxR3ezC8AKslxEDJrOsMV0kjJZxq0N1mRAptP_iZyVwp6X2qGdVuuk5Tu4KbU7Dp6ThvavOUaN8PRHnArYSK1awb_3vSrmUB72LF8RgD_AmG4VO

 

The command “ls” lists the files and folder. In the above screen shot the ‘ls’ command lists the “data” directory that we just created with the “mkdir data” command.

Use the following command to mount our new /dev/xvdf volume in this new ‘data’ directory using the following command;

sudo mount /dev/xvdf data

rxUCt4O8rH58A_2vkIkscYsRZ7_qZDfIXrqPDG5JBc412Kk6HqUbwOiCZLItYXCv6qlnF2yl4n7F2fdMRdl_9ht8mr19hiWcStCibuqGbILVe5JQA4U_tzcseXjPpcXOCm045jk2

Now, the new data volume is available for you to work like any other directory in your instance.

Once you are done working, you could unmount the device and then detach it from the instance. This detached volume could then be attached to any other instance, any other time or archived for future use or shared with others.

1.6. Unmounting the volume

Run the below command to unmount the ‘data’ volume that we just mounted;

sudo umount data

Q3Wav-K0CTj2abmmGGZySxsRm77RdEpsOkLeS42VrRd7JRBgLB2i3PqhSL0wDm8_PazEO6cUhc9HRi1TzLKGX7sQ0AwsGHw1B0ZpB07ciFny4ukGLOZIARcTH_y2H6SeVtcRJE8o

 

1.7. Detach volume

To detach a volume from an instance, select that volume from the “Volumes” menu, click Actions and chose “Detach Volume” option. Confirm “Yes Detach” in the prompting window, to detach this volume from your running instance.

 

ttXgOLAPiC6z04nkmOl6ANu2U7YUIjUp5zGbb2v05HrxIScUIOVojNfFP0GbDFEc9a62QgZ22EKRQflr2DDJhjjLxZr44DGlviSnUJPNT_Zl3y3yHbwOSpmfyVFC0x21XxJ1Dk4n

1.8. Delete volume

If you dont want to volume anymore and if you dont want to be paying for this storage, you could delete the volume, using the Volume menus, Actions - Delete Volume option;

tW4cvwPIOHoa8O-wGva_XKoh0WSfs-IHRw9avXuAXfJNT6cRpMGs8n3kITLKIHoJqnFr3mMM4kXpWVr1Jp_uyaahpzooZG8UU2RC3cvol4gOABVbvqlIP3Jq0hf2IyDTU4zkJdS3

 

2. Using AWS Simple Storage Service (S3)

Any object/data could be easily and securely stored in the cloud using AWS S3 services. There are several different ways to do this, with a bunch of different pricing options. Here we will learn to use the basic S3 operations for low cost data storage.

2.1. Access S3

An S3 bucket is like a folder to store your files. It is unique and accessed as a web url. Click the “Services” menu option in the AWS management console and click “S3” under the “Storage” section;

kc5IrntK8zX5clsEwI3zwL7rrqSw-LSFMaenCTQuoJi55-FhyntKed7RwgxVZTsPTawepPT1F6GSAcVkhDINuj09BlXSbNgX2mPqgOQiIvXq9kziSpfMuHsXSxnjcHmyfyPI2rqa

2.2. Create S3 bucket

In the Amazon S3 service window, click the “Create bucket” button.

 

Gc0QMJ1Gliizya48CH6ujwfVEm53liL_694Em3aWB2yrjgx33rt66EJsXMjjsn_cGz0ZSGUqdiYLJVDv3U3-8tcY2ifEZgJSDUKUY-bgrter3JY41fMFXiFGBxq-xJGQqhSnxZaL


Enter a unique name for your bucket and click “Next” in the “Create bucket” window.

oZ3-hxbqpGPQHEbVheEMSvkjLkz77S5hwjj5LDpZxBvCTTOz6AvoyaulLm-WRXKlxZ8TqFC6rmZuy0za2Mgt6Tf4tDKsjwzBDaic03BzvhgHiL6OOqcgcK7M_LwuFHhU8CeylaYJ


Click “Next” in the next two windows and then click “Create bucket” in the last window to create your S3 bucket.

2.3. Upload data to S3 bucket

In the Amazon S3 window, click on the name of the bucket where you want to upload/download data.

 

pD2d6n2ZDlRieRyTujb3aHdYBk3zziZMS9nLukLV6rnO_nra5RYOLCkUhmewy_gYMMmkiUawfcupZJAA0l90VbTr9e9fSKyd2RP5MtshyXx6cXeSShp-QD6YtZ1-W5mYl7shPHNJ

 


In the bucket window, click “Upload” button.

DBTnnv5HuuWPocrjc4qiJmq5peC80A7Z4mvnTAhzBzTmR2Li2X7ods-hauEiOSovsMPKPyvgcKN2OshsTStPrF0fy0CpnmOoSJeMf_VGoaiFVAhmMNnYwql1cOrjUi1rnfYXwVTk

 


In the resulting window, either drag and drop files from your local computer or Click “Add files” button to browse and add files from your local computer to the S3 bucket.

 

FDH5HsrQemsbPJ8vgbH5W_h_DWfgYDfDrD8CGoj3LTSHjjefCNm8806iSdD77ueRxwLAeHoR-QpLCXgpS_GVb0lJOiGViCoC79GxKG_VvLM5_fu2K7BQ7cyd983CWYNQ7uQs2E55

 

Once your files are added, click the “Upload” button to upload your files to the S3 bucket.

2.4. Accessing stored data

The S3 bucket and its files can be accessed just by clicking on the bucket name and clicking on the files of interest (for downloading or sharing).

QnBshVIcHj-P9boAjG7uBmIjipxKB-QdECkSWw1rXWG2wJ4FcVfX918SiOq7D9mBMB39l8fAURNG68dUmbiTKrTrqPP1RAJVJJ_csQVd_LqALv-Dj1dnp5bC8IjSz5A6NrBNtZ8p