AWS Classroom Series – 30/Aug/2020

Elastic Volumes

  • Lets create one windows ec2 instance with t2.micro and one linux machine with t2.micro Preview

Expanding EBS root volume on EC2 windows instance

  • Login into Windows ec2 and select disks from server manager Preview
  • Now lets change the volume size from 30 GB to 32 GB and see how to reflect that in windows instance without restarting the windows ec2 instance Preview Preview
  • Run diskmgmt.msc command to open disk management & do the refresh.

Preview Preview Preview

  • Login into linux instance & execute the following command
sudo df -Th

Preview

  • Now lets change the volume size from 8 GB to 10 GB for the linux instance
  • Execute the following commands on linux
  • List the block devices
sudo lsblk

Preview

  • Now we need to extend the partition, to do that we need to execute the following command
sudo growpart /dev/xvda 1

Preview

  • Now we need to extend the filesystem
    • If the filesystem is ext2,ext3 or ext4
    sudo resize2fs /dev/xvda1
    
    • If the filesystem is xfs
    sudo xfs_growfs /dev/xvda1
    
    Preview
  • Now lets verify the effective file system sizes
sudo df -h

Preview

AWS CLI for EBS Volumes

  • Lets use aws cli to create a volume in us-west-2c az with 1 GB size and General Purpose volume. Refer Here for the list of ec2 actions

  • Now lets try to search for volume based commands to find the create volume Preview

  • Now open this command and navigate to synopsis Refer Here

aws ec2 create-volume
--availability-zone <value>
[--encrypted | --no-encrypted]
[--iops <value>]
[--kms-key-id <value>]
[--outpost-arn <value>]
[--size <value>]
[--snapshot-id <value>]
[--volume-type <value>]
[--dry-run | --no-dry-run]
[--tag-specifications <value>]
[--multi-attach-enabled | --no-multi-attach-enabled]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
  • The command would be
aws ec2 create-volume --availability-zone us-west-2c --size 1 --volume-type gp2

Preview

  • Now lets try to describe the volume which we created. The volume id in the above case is "vol-014f9f2b3e8487eb2". Now lets describe this volume Refer Here
  • The command would be
aws ec2 describe-volumes --volume-ids "vol-014f9f2b3e8487eb2"

Preview

  • We can also some filters
aws ec2 describe-volumes --filters "Name=availability-zone,Values=us-west-2c"

Preview

  • Lets delete the volume Preview
  • Now create a linux based ec2 instance with t2.micro (CLI/console) Preview
  • Now create a volume of 1 GB with general purpose in the az where your ec2 instance is created and make a note of volume id: "vol-07aa3361c8055b815" Preview
  • Make a note of ec2-instance id and try to attach volume to ec2-instance (i-0c21d1c4e7c38c948)
aws ec2 attach-volume --volume-id "vol-07aa3361c8055b815" --instance-id i-0c21d1c4e7c38c948 --device "/dev/xvdb"

Preview Preview

  • now lets login into ec2 instance and mount the volume to some drive Preview Preview
  • Lets modify the volume from 1 GB to 2 GB
aws ec2 modify-volume --volume-id "vol-07aa3361c8055b815" --size 2

Preview

  • Now login into ec2 instance and expand the volume Preview
  • Exercise: Create CLI for the below activities
    1. Create an AWS CLI Command to create the snapshot of the volume created. Preview
    2. From snapshot try to create a volume in a different AZ
    3. Copy the snapshot to different region

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin