Create Elastic Block Storage Volume

To create an Elastic Block Storage (EBS) volume in AWS, you can follow these steps. I'll guide you through both the AWS Management Console method (graphical interface) and the AWS CLI method (command-line interface).

Method 1: Using the AWS Management Console

  1. Log in to the AWS Management Console:

  2. Navigate to the EC2 Dashboard:

    • In the AWS console, search for "EC2" in the search bar and select EC2 from the services dropdown.
  3. Go to Elastic Block Store (EBS):

    • From the EC2 dashboard, scroll down to find the Elastic Block Store section in the left-hand menu.

    • Click on Volumes.

  4. Create a New Volume:

    • Click on the Create Volume button at the top of the page.

  5. Configure Volume Settings:

    • Volume Type: Choose the type of volume you need (e.g., gp3, gp2, io2, st1, etc.).

    • Size: Specify the size of the volume in GB.

    • Availability Zone (AZ): Select the Availability Zone where your EC2 instance resides. Volumes can only be attached to instances in the same AZ.

    • IOPS: If you're using Provisioned IOPS SSD (io2, io1), specify the number of IOPS.

    • Throughput: If you’re using gp3, you can adjust the throughput settings.

    • Encryption: Check the box to encrypt the volume. You can use AWS’s Key Management Service (KMS) to manage your encryption keys.

  6. Review and Create:

    • Review your settings and click Create Volume.

  7. Attach the Volume to an EC2 Instance:

    • After creating the volume, you will see it in the Volumes list.

    • Select the volume, click on the Actions dropdown, and choose Attach Volume.

    • Select the EC2 instance to which you want to attach the volume and choose the correct Device Name (e.g., /dev/sdf for Linux or /dev/xvdf).

    • Click Attach to complete the process.

  8. Mount the Volume (Linux EC2 instance):

    • After attaching the volume, SSH into your EC2 instance to mount the volume to your file system.

    • Check if the volume is attached:

        lsblk
      

      The new volume should appear, but it won’t be mounted yet.

    • Create a filesystem (if the volume is new):

        sudo mkfs -t ext4 /dev/xvdf
      
    • Mount the volume:

        sudo mkdir /mnt/myebsvolume
        sudo mount /dev/xvdf /mnt/myebsvolume
      
    • Verify the mounted volume:

        df -h
      

Method 2: Using the AWS CLI

To use the AWS CLI to create an EBS volume, make sure the AWS CLI is installed and configured on your machine.

  1. Configure AWS CLI: If you haven't configured your AWS CLI, run:

     aws configure
    

    Enter your AWS Access Key ID, Secret Access Key, region, and output format (e.g., JSON).

  2. Create an EBS Volume: Use the following command to create an EBS volume:

     aws ec2 create-volume \
       --size 10 \
       --volume-type gp3 \
       --availability-zone us-east-1a \
       --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=MyEBSVolume}]'
    
    • --size: Size of the volume in GB.

    • --volume-type: The type of volume (gp3, gp2, io2, etc.).

    • --availability-zone: Specify the AZ where your EC2 instance resides.

    • --tag-specifications: Add tags to help identify the volume.

  3. Attach the Volume to an Instance:

     aws ec2 attach-volume \
       --volume-id vol-1234567890abcdef0 \
       --instance-id i-1234567890abcdef0 \
       --device /dev/xvdf
    
    • --volume-id: The ID of the EBS volume (from the previous step).

    • --instance-id: The ID of the EC2 instance to which the volume will be attached.

    • --device: The device name (e.g., /dev/xvdf).

  4. Mount the Volume on Linux Instance: After attaching the volume, follow the same steps as mentioned in the AWS Management Console method to mount the volume.


Conclusion

Creating and managing EBS volumes is straightforward using both the AWS Management Console and the AWS CLI. EBS provides flexible, scalable, and persistent storage solutions for your EC2 instances. Whether you're running databases, applications, or general data storage, EBS can handle various workloads with its range of volume types tailored for performance or cost efficiency.