How to create and automatically mount AWS EFS storage in AWS EC2 instance?

How to create and automatically mount AWS EFS storage in AWS EC2 instance?

How to create and automatically mount AWS EFS storage in AWS EC2 instance?

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

Today we are going to discuss, how to create and automatically mount an Elastic File Share (EFS) to an EC2 instance using AWS CLI.

What is Amazon Elastic File System (EFS)?

Amazon Elastic File System (Amazon EFS) provides a simple, serverless, set-and-forget elastic file system for use with AWS Cloud services and on-premises resources. Amazon EFS supports the Network File System version 4 (NFSv4.1 and NFSv4.0) protocol, so the applications and tools that you use today work seamlessly with Amazon EFS. Multiple compute instances, including Amazon EC2, Amazon ECS, and AWS Lambda, can access an Amazon EFS file system at the same time, providing a common data source for workloads and applications running on more than one compute instance or server.

EFS storage classes:

Amazon EFS offers a range of storage classes that are designed for different use cases. These include EFS Standard, EFS Standard–Infrequent Access (Standard-IA), EFS One Zone, and EFS One Zone–Infrequent Access (EFS One Zone-IA).

EFS Standard and Standard-IA storage classes are regional storage classes that are designed to provide continuous availability to data, even when one or more Availability Zones in an AWS Region are unavailable. They offer the highest levels of availability and durability by storing file system data and metadata redundantly across multiple geographically separated Availability Zones within a Region.

EFS One Zone and One Zone–IA storage classes are designed to provide continuous availability to data within a single Availability Zone. The EFS One Zone storage classes store file system data and metadata redundantly within a single Availability Zone in an AWS Region. Because they store data in a single AWS Availability Zone, data that is stored in these storage classes might be lost in the event of a disaster or other fault that affects all copies of the data within the Availability Zone, or in the event of Availability Zone destruction.

EFS Throughput modes:

A file system’s throughput mode determines the throughput available to your file system. Amazon EFS offers two throughput modes, Bursting Throughput and Provisioned Throughput. Read throughput is discounted to allow you to drive higher read throughput than write throughput. Depending on the AWS Region, the discount for reads is between 1.66 and 3x.

Next, we will create a EFS file share and mount the EFS file share to an AWS EC2 instance.

Prerequisites:

AWS CLI installed and configured.

How to create and automatically mount AWS EFS storage in AWS EC2 instance?

Step 1: Create a EFS file share using AWS CLI.

Step 2: Create a new VPC with public subnet and security group for EC2 and EFS.

Step 3: Create a EFS mount target using AWS CLI.

How to create and automatically mount AWS EFS storage in AWS EC2 instance?

Step 4: Create a new EC2 instance and automatically mount the EFS file share to the EC2 instance using user data.

Next, we will connect to the EC2 instance and create a new file in the EFS file share.

Step 5: Connect to the EC2 instance and create a file on EFS file share.

Step 6: Clean up.

Hope you have enjoyed this article. To get more details in AWS EFS, please refer the below documentation

https://docs.aws.amazon.com/efs/index.html

Leave a Reply

Close Menu