Introduction
AWS is a powerful cloud platform that provides a variety of services to satisfy various business requirements. Amazon EC2 (Elastic Compute Cloud) and Amazon EBS (Elastic Block Store) are two of its most popular offerings. When combined, they offer versatile and scalable computing and storage options. In this blog we will explain how to connect EBS volumes into EC2 Instance.
What is EBS?
Amazon Elastic Block Store (EBS) is a scalable and high-performance storage service designed for use with EC2 instances. It provides persistent block storage, meaning data is retained even if the associated EC2 instance is stopped or terminated.
Benefits of Using EBS with EC2
- Scalability: Add or resize storage volumes based on application requirements.
- Persistence: Retain critical data independently of EC2 instances.
- High Performance: EBS provides consistent performance for applications with high IOPS requirements.
- Backup and Recovery: Create snapshots of EBS volumes for disaster recovery.
- Multiple Volume Attachments: Attach multiple volumes to a single EC2 instance to segregate application data.
Common Use Cases
- Application Storage: Host databases or application logs.
- Backup Solutions: Store snapshots or backup files.
- Data Analytics: Process large datasets with persistent storage.
Two types of EBS Volumes
There are 3 types of EBS Volumes available in AWS:
- Solid state drive volumes
- Hard disk drive volumes
- Previous generation volumes
1. Solid state drive volumes
SSD-backed volumes are optimized for transactional workloads, where the volume performs a lot of small read/write operations. The performance of such volumes is measured in IOPS (input/output operations per second).
2. Hard disk drive volumes
HDD-backed volumes are designed for large sequential workloads where throughput is much more important (and the performance is measured with MiB/s.
3. Previous generation volumes
Previous generation volumes supported by magnetic drives are known as magnetic (standard) volumes. They work well for workloads with tiny datasets where performance is not the main concern and data is retrieved infrequently. These volumes can range in size from 1 GiB to 1 TiB and produce an average of 100 IOPS with a burst potential of hundreds of IOPS.
Step by Step Guide to Attaching EBS to EC2
Step 1: Launch an EC2 Instance
Please follow steps for creating EC2 Instance for this Blog:
- Login to AWS Management Console.
- Search for EC2 in the services menu.
- Click on “Launch Instance” and configure the instance with the desired settings.
- Add a key pair for secure SSH access and launch the instance.

Step 2: Create an EBS Volume
EBS volumes are created independently of EC2 instances.
- Navigate to the EBS Dashboard:
- Go to the AWS Management Console and search for “Elastic Block Store.”
- Click on Volumes under the EBS section.
2. Click “Create Volume“
- Specify the size of the volume in GB (e.g., 10 GB).
- Choose the volume type:
- General Purpose SSD (gp3/gp2): Suitable for general-purpose workloads.
- Provisioned IOPS SSD (io1/io2): For applications requiring high IOPS.
- Magnetic (Standard): Cost-effective for infrequently accessed data.

Select the availability zone of your EC2 instance (both must be in the same zone).

3. Create and Name the Volume
- Add a meaningful name (e.g., “Devops Horizon Storage”).
- Click Create Volume.

Step 3: Attach the EBS Volume to the EC2 Instance
Once the volume is created, attach it to your EC2 instance.
- Locate the EBS Volume:
- In the EBS dashboard, find the volume you just created.
- In the EBS dashboard, find the volume you just created.
- Attach the Volume:
- Click on the Actions button and select Attach Volume.
- Click on the Actions button and select Attach Volume.

- Choose the target EC2 instance from the dropdown list.
- Specify a device name for the volume.

Step 4: Connect to the EC2 Instance
To format and mount the EBS volume, connect to the EC2 instance via SSH.
- Obtain the Public IP Address
- From the EC2 dashboard, locate the public IPv4 address of your instance.
- From the EC2 dashboard, locate the public IPv4 address of your instance.
- Connect via SSH
- Use the following command
ssh – Keypair ec2-user@<public-ip>

Step 5: Prepare the EBS Volume
The attached volume must be formatted and mounted before use.
- Check Attached Volumes
- Run the following command to list attached volumes
- lsblk
2. Format the Volume
- Use the mkfs command to format the volume
sudo mkfs -t ext4 /dev/xvdbb
3. Create a Mount Point
- Create a directory to mount the volume
sudo mkdir /mnt/mydata
4. Mount the Volume
- Mount the volume to the created directory:
sudo mount /dev/xvdbb /mnt/mydata
5. Verify Mounting:
- Use the df -h command to verify the volume is mounted:
df -h

Step 6: Persist the Mount
To ensure the volume remains mounted after instance reboots, update the /etc/fstab file.
- Edit /etc/fstab
- Open the file with a text editor:
sudo vi /etc/fstab
2. Add an Entry
- Add the following line:
/dev/xvdbb /mnt/mydata ext4 defaults,nofail 0 2
3. Save and Exit
- Save the file and exit the editor.
4. Test the Configuration
- Unmount and remount all filesystems:
sudo umount /mnt/mydata
sudo mount -a
Best Practices for Using EBS with EC2
1. Choose the Right Volume Type
- General Purpose SSD: For everyday workloads like web servers and small databases.
- Provisioned IOPS SSD: For mission-critical applications requiring high throughput.
- Cold HDD: For archival storage.
2. Implement Backup Strategies
- Use EBS snapshots to create incremental backups of your volumes.
3. Monitor Performance
- Use Amazon CloudWatch to track IOPS, throughput, and latency metrics.
4. Ensure Data Security
- Enable encryption for EBS volumes to protect sensitive data.
5. Optimize Costs
- Detach and delete unused volumes to avoid unnecessary charges.
Use Cases for Attaching EBS to EC2
1. Hosting Databases
EBS volumes are ideal for hosting MySQL, PostgreSQL, or NoSQL databases requiring persistent storage.
2. Application Storage
Use EBS for storing logs, temporary files, or static application assets.
3. Data Analysis
Attach multiple EBS volumes to process large datasets with high performance.
Conclusion
A key step in handling scalable and durable storage in the AWS cloud is linking an EBS volume to an EC2 instance. You can add, configure, and optimize storage for your applications by following these guidelines. Amazon EBS provides the performance and versatility needed for success, whether you’re backing up data, running a database, or processing extensive data sets.
Combining EBS with EC2 can create new possibilities for cost-effectiveness, scalability, and data longevity as your understanding of the cloud expands. To make the most of AWS’s powerful computing and storage capabilities, begin experimenting today. Please visit DevOps Horizon for more DevOps and Cloud Blogs