A Guide to Managing AWS EC2 Instances and EBS Volumes

A Guide to Managing AWS EC2 Instances and EBS Volumes

EC2 and EBS Management for AWS Beginners

Introduction

In the world of cloud computing, Amazon Web Services (AWS) is a leading platform offering a wide range of services to build scalable and flexible applications. Among these services, EC2 (Elastic Compute Cloud) and EBS (Elastic Block Store) are essential for creating and managing virtual servers and their storage. This guide will walk you through launching an EC2 instance, creating and attaching an EBS volume, and resizing the volume to meet your storage needs.

Step 1: Launching a Linux EC2 Instance

The first step is to create an EC2 instance, which is a virtual server in AWS's cloud. Here's how to do it:

  1. Log in to AWS Management Console:

  2. Navigate to EC2 Dashboard:

    • Type "EC2" in the search bar and select EC2 to access the EC2 Dashboard.
  3. Launch an Instance:

    • Click the "Launch Instance" button.

    • Choose an Amazon Machine Image (AMI): Select "Ubuntu Server 20.04 LTS (HVM), SSD Volume Type".

    • Choose an Instance Type: Select t2.micro (eligible for the free tier).

    • Configure Instance:

      • Network: Choose the default VPC.

      • Subnet: Choose a subnet in the US-East-1 (N. Virginia) region.

      • Enable Auto-assign Public IP.

    • Add Storage: Keep the default settings.

    • Add Tags: Add a tag to identify your instance (e.g., Key: Name, Value: MyLinuxServer).

    • Configure Security Group:

      • Add a new security group with the following rules:

        • Type: SSH, Protocol: TCP, Port Range: 22, Source: your IP address (e.g., 203.0.113.0/24).
  4. Review and Launch:

    • Review your instance settings and click "Launch".

    • Select an existing key pair or create a new one, then click "Launch Instances".

Step 2: Stopping the EC2 Instance

To attach an EBS volume, it's often recommended to stop the EC2 instance to avoid data corruption and ensure a smooth attachment process.

  1. Stop the EC2 Instance:

    • In the EC2 Dashboard, select your instance.

    • Click on "Instance State" and then "Stop Instance".

    • Confirm the action.

Step 3: Creating and Attaching an EBS Volume

Next, you'll create a new EBS volume and attach it to your EC2 instance.

  1. Create an EBS Volume:

    • Go to the EC2 Dashboard.

    • Under "Elastic Block Store", click "Volumes".

    • Click "Create Volume".

    • Configure the volume:

      • Size: 20 GiB.

      • Availability Zone: Select the same availability zone as your EC2 instance.

    • Click "Create Volume".

  2. Attach the EBS Volume to the EC2 Instance:

    • Select the newly created volume from the Volumes list.

    • Click "Actions" and select "Attach Volume".

    • Choose your stopped instance from the "Instance" dropdown menu.

    • For "Device", use the default value (e.g., /dev/xvdf).

    • Click "Attach".

  3. Start the EC2 Instance:

    • In the EC2 Dashboard, select your instance.

    • Click on "Instance State" and then "Start Instance".

    • Wait for the instance to be in the "running" state.

  4. Connect to Your EC2 Instance:

    • In the EC2 Dashboard, select your instance.

    • Click "Connect" and follow the instructions to connect using SSH.

  5. Check the Attached Volume:

    • Run the following command to check the attached volume:

        lsblk
      
    • You should see the volume listed (e.g., /dev/xvdf).

Step 4: Resizing the Attached Volume Using AWS Management Console

If you need more storage, you can easily resize your EBS volume from the AWS Management Console.

  1. Resize the EBS Volume:

    • In the EC2 Dashboard, select "Volumes" under "Elastic Block Store".

    • Select your attached volume and click "Actions" -> "Modify Volume".

    • Change the size to a larger value (e.g., 30 GiB) and click "Modify".

    • Confirm the modification.

  2. Start the EC2 Instance:

    • In the EC2 Dashboard, select your instance.

    • Click on "Instance State" and then "Start Instance".

    • Wait for the instance to be in the "running" state.

  3. Connect to Your EC2 Instance:

    • In the EC2 Dashboard, select your instance.

    • Click "Connect" and follow the instructions to connect using SSH.

  4. Check the Attached Volume:

    • Run the following command to check the attached volume:

        lsblk
      
    • You should see the volume listed (e.g., /dev/xvdf).

Conclusion

By following this step-by-step guide, you have successfully launched an EC2 instance, created and attached an EBS volume, resized the volume, and confirmed the new size on your instance. This hands-on experience is valuable for efficiently managing cloud resources, which is a crucial skill in today's tech-driven world.

Additional Resources

Did you find this article valuable?

Support Mantra Tech by becoming a sponsor. Any amount is appreciated!