🚀Exploring AWS EBS and EFS for Efficient Storage🚀
Tags: aws, devops, iam, awscpp
Published: 2023-08-18 19:54:27

With Step-by-Step Guide to Assigning AWS EBS and EFS to EC2 Instances☁️☁️☁️

**TABLE OF CONTENTS**

Introduction
AWS Elastic Block Store (EBS):
Here are some key points to consider:
Assigning EBS Volumes to EC2 Instances:
AWS Elastic File System (EFS)
Let's explore some key aspects of EFS:
Assigning EFS File Systems to EC2 Instances:
Conclusion:

**Introduction 👩‍💻
Welcome to another my another blog If you're joining here for the first time, I encourage you to check out my previous blogs to gain a comprehensive understanding of cloud computing. In this blog, we'll delve into two crucial storage solutions offered by Amazon Web Services (AWS): Elastic Block Store (EBS) and Elastic File System (EFS). As the cloud landscape evolves, it's essential to stay up to date with the latest advancements. As Theodore Roosevelt once said, "Believe you can and you're halfway there." So, let's embark on this journey of discovery and unlock the potential of AWS storage solutions!

**AWS Elastic Block Store (EBS):**
AWS Elastic Block Store (EBS) is a block-level storage service that provides persistent storage volumes for your Amazon EC2 instances. It enables you to create, attach, and detach storage volumes to EC2 instances, offering durability, availability, and low-latency performance. Here are some important aspects to consider:

1.**Volume Types**: AWS EBS offers several volume types, each optimized for specific use cases. The available volume types include:

General Purpose SSD (_gp2/gp3_): Designed for a broad range of workloads, including system boot volumes, small to medium-sized databases, and development/test environments.

Provisioned IOPS SSD (_io1/io2_): Suitable for high-performance workloads that require consistent and predictable I/O performance, such as large databases and transactional applications.

Throughput Optimized HDD (_st1_): Ideal for frequently accessed, throughput-intensive workloads, including big data and data warehousing.

Cold HDD (_sc1_): Designed for infrequently accessed workloads, such as file servers and archival storage.

2.**Snapshots and Backups**: EBS allows you to create point-in-time snapshots of your volumes, which are stored in Amazon S3. These snapshots serve as backups and can be used to restore volumes or create new volumes in different availability zones or regions. 

3.**Availability and Durability**: EFS provides a highly available and durable storage solution. Your data is automatically replicated across multiple Availability Zones (AZs) within a region, ensuring that it is accessible even in the event of an AZ-level failure. 

**Security**: EFS integrates with AWS Identity and Access Management (IAM) to control access to your file system. 

**Performance Modes**: EFS offers two performance modes to optimize file system performance based on your workload requirements:

**General Purpose mode**: Suitable for a broad range of workloads, including web serving, content management systems, and development environments.

**Max I/O mode**: Designed for workloads with high levels of aggregate throughput and IOPS, such as big data analytics and media processing.

**Throughput Provisioning**: With EFS, you can provision throughput to meet the demands of your applications.

**Integration with AWS Services**: EFS integrates seamlessly with other AWS services. For example, you can mount an EFS file system on multiple EC2 instances to enable data sharing and collaboration. 

**Here are some key points to consider:**

**Storage Limits**: EBS volumes can be provisioned from 1 GB to 16 TB in size, providing ample flexibility to cater to various storage requirements. Additionally, you can take advantage of Elastic Volumes to increase capacity, modify volume types, and adjust performance as needed without disrupting your EC2 instances.

**Pricing**: AWS EBS pricing is based on the size of the storage volumes you provision, the amount of data transferred, and the operations performed. It's important to familiarize yourself with the pricing details on the AWS website to estimate costs accurately.

**Usage**: EBS volumes are well-suited for a wide range of use cases, including database storage, boot volumes, and data warehousing. They provide consistent and reliable performance for applications requiring low-latency access to data.

####Assigning EBS Volumes to EC2 Instances:

Let's take a look at the steps to assign an EBS volume to an EC2 instance:

**Launch an EC2 instance**: First, you need to launch an EC2 instance if you haven't done so already. Go to the AWS Management Console, navigate to the EC2 service, and click on "Launch Instance". Select the desired instance type, configure the instance details, and proceed through the remaining steps of the launch wizard.

**Create an EBS volume**: Once the instance is launched, go to the EC2 service and click on "Volumes" in the left-hand menu. Click on "Create Volume" and specify the desired volume size, availability zone, and other options. Click "Create" to create the EBS volume.

**Attach the EBS volume to the EC2 instance**: After the volume is created, select the volume from the list and click on "Actions" > "Attach Volume". In the "Instance" field, select the EC2 instance to which you want to attach the volume. Specify the device name (e.g., /dev/xvdf) to which the volume will be attached, and click "Attach".

**Connect to the EC2 instance**: Now, you need to connect to the EC2 instance to perform further steps. You can use SSH for Linux instances or Remote Desktop Protocol (RDP) for Windows instances, depending on your instance's operating system.

**Identify the attached EBS volume**: Once you're connected to the EC2 instance, you need to identify the attached EBS volume and its device name. Run the following command to list the available block devices:
```
 lsblk
```
The output will display the available block devices along with their device names (e.g., `/dev/xvdf`).

**Create a file system on the EBS volume**: Use the appropriate command to create a file system on the attached EBS volume. For example, if the volume is formatted with the ext4 file system, you can use the following command:

```
 sudo mkfs -t ext4 /dev/xvdf

```
Replace `/dev/xvdf` with the device name of your EBS volume.

**Mount the EBS volume**: Create a directory on the EC2 instance where you want to mount the EBS volume. For example, you can create a directory called "ebs-mount" using the following command:

```
sudo mkdir /ebs-mount
```
Then, mount the EBS volume to the directory using the following command:

```
 sudo mount /dev/xvdf /ebs-mount

```
Again, replace `/dev/xvdf` with the device name of your EBS volume.

**Configure automatic mounting (optional)**: If you want the EBS volume to be automatically mounted every time the EC2 instance restarts, you can configure it in the instance's /etc/fstab file. Open the file using a text editor, such as nano, and add the following entry at the end:

```
 /dev/xvdf   /ebs-mount   ext4   defaults,nofail   0   2
```
Save the file and exit the text editor.

That's it! You have successfully assigned an EBS volume to your EC2 instance. The EBS volume will now be accessible and mounted on the specified directory within the instance.

Understanding the pricing details, performance characteristics, and specific requirements of your workload will help you make informed decisions when provisioning and utilizing EBS volumes. By leveraging EBS, you can achieve scalable, reliable, and performant storage for your EC2 instances, enabling you to build robust and resilient applications in the AWS cloud.

Remember, exploring the AWS EBS documentation and consulting the AWS Well-Architected Framework can provide further insights and best practices for utilizing EBS effectively in your cloud infrastructure.

## AWS Elastic File System (EFS)

AWS Elastic File System (EFS) provides scalable and fully managed file storage for Amazon EC2 instances.

**Scalability and Elasticity**: EFS is designed to scale automatically, providing virtually unlimited storage capacity as your data grows. The file system expands and contracts seamlessly based on the amount of data stored, eliminating the need for manual capacity planning. With EFS, you don't need to worry about running out of storage or performance bottlenecks.

**Performance**: EFS offers low-latency performance and high throughput for a wide range of workloads. It uses the Network File System (NFS) protocol version 4, which provides POSIX-compliant file system access. EFS also supports file system caching, allowing you to optimize performance by reducing the number of requests sent to the EFS service.

**Availability and Durability**: EFS provides a highly available and durable storage solution. Your data is automatically replicated across multiple Availability Zones (AZs) within a region, ensuring that it is accessible even in the event of an AZ-level failure. This built-in redundancy enhances data durability and provides high availability for your applications.

**Security**: EFS integrates with AWS Identity and Access Management (IAM) to control access to your file system. You can set fine-grained permissions and manage access at the file, directory, and user levels. Additionally, you can encrypt your EFS data at rest using AWS Key Management Service (KMS) to ensure data confidentiality.

**Performance Modes**: EFS offers two performance modes to optimize file system performance based on your workload requirements:

**General Purpose mode**: Suitable for a broad range of workloads, including web serving, content management systems, and development environments.

**Max I/O mode**: Designed for workloads with high levels of aggregate throughput and IOPS, such as big data analytics and media processing.

**Throughput Provisioning**: With EFS, you can provision throughput to meet the demands of your applications. You can set the throughput mode to "Bursting" for most workloads, which provides high throughput as needed. For workloads that require sustained high throughput, you can choose the "Provisioned" mode and set the desired throughput level.

**Integration with AWS Services**: EFS integrates seamlessly with other AWS services. For example, you can mount an EFS file system on multiple EC2 instances to enable data sharing and collaboration. EFS also integrates with AWS Lambda, Amazon ECS, and Amazon EKS, allowing you to build serverless applications and containerized workloads that require shared file storage.

## Let's explore some key aspects of EFS:

Storage Limits: EFS provides virtually unlimited storage capacity, allowing you to scale your file system seamlessly as your storage needs grow. 

Pricing: EFS pricing is based on the storage used, the number of file system requests, and the data transferred. 

Usage: EFS is well-suited for a variety of use cases, including content management systems, web serving, container storage, and big data analytics.

### Assigning EFS File Systems to EC2 Instances:

Assigning an EFS file system to an EC2 instance is a straightforward process:

**Create an Amazon EFS file system:**

Open the AWS Management Console and navigate to the Amazon EFS service.

Click on "Create file system" and provide a unique name, choose the VPC and subnet in which the EC2 instances are located, and configure the security groups.

Adjust the performance mode and throughput mode according to your requirements.

Optionally, configure lifecycle management policies and encryption settings.

Click on "Create file system" to create the EFS file system.

**Create the mount targets:**

After the EFS file system is created, click on the file system's ID to open its details page.

Under the "Mount targets" section, click on "Create mount target".

Select the appropriate subnet and security group for the mount target.

Click on "Create mount target" to create the mount target. Repeat this step if you need multiple mount targets in different availability zones.

**Retrieve the file system's ID and DNS name:**

From the details page of your EFS file system, note down the "File system ID" and "DNS name" values. You will need them later to mount the EFS file system on EC2 instances.

**Launch or select the EC2 instances:**

Open the EC2 service in the AWS Management Console.

Launch new EC2 instances or select existing ones in the same VPC and subnet as the EFS file system.

Ensure that the EC2 instances have the necessary permissions to access the EFS file system.

**Install the necessary NFS client packages:**

Connect to your EC2 instances using SSH.

Install the NFS client package by running the appropriate command for your Linux distribution. For example:

Ubuntu/Debian: sudo apt-get install nfs-common

Amazon Linux: sudo yum install nfs-utils

**Mount the EFS file system on the EC2 instances**:

Run the following command on each EC2 instance, replacing `fs-12345678 `with your EFS file system ID and fs-dns-name with your EFS file system's DNS name:

```
  sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 <fs-dns-name>:/ /mnt/efs

```
**Verify the mount:**

Run `df -h` to verify that the EFS file system is successfully mounted. You should see a new entry for the EFS file system mounted at `/mnt/efs`.

That's it! You have successfully assigned an EFS file system to your EC2 instances. The EFS file system will now be accessible to the EC2 instances, allowing them to share data and files.

**Conclusion**
In this blog, we explored two key storage solutions offered by AWS: Elastic Block Store (EBS) and Elastic File System (EFS). We discussed storage limits, pricing considerations, and the steps to assign them to EC2 instances. Remember to refer to AWS documentation for detailed instructions and to stay updated with the latest features and enhancements. As we conclude, let's remember the words of Mahatma Gandhi, "The future depends on what you do today." So, seize the opportunity to leverage AWS storage solutions and unlock the full potential of your cloud infrastructure.

Stay tuned for our next blog in the Cloud Series, where we will continue our journey of exploring the intricacies of cloud computing. Until then, keep learning and embracing the power of the cloud!

Please share your thoughts and opinions on this topic in the comments section below.

The above information is up to my understanding and learning experience. Suggestions are always welcome.☁️🌟🔓

~Sanket Kalekar

#DevOps #AWS #EBS #EFS #Cloud-Computing

Connect with me :
          https://www.linkedin.com/in/sanketkalekar/
LinkedIn