4.20 Elastic File System (EFS) Lab
Last updated
Was this helpful?
Last updated
Was this helpful?
Amazon Elastic File System (Amazon EFS) is a file storage service for Amazon EC2 instances. It is a kind of file system. EFS is easy to use and provides a simple interface that allows you to create and configure file systems quickly and easily. With EFS, storage capacity is elastic, growing and shrinking automatically as you add and remove files, so your applications have the storage they need, when they need it.
Unlike EBS volumes, EFS allows you to attach one EFS to multiple EC2 instances.
Supports the Network File System version 4 (NFSv4) protocol.
You only pay for the storage you use (no pre-provisioning required). We just need to start EFS and put files on it and EFS will charge 30 cents per Gigabytes.
It can scale up to Petabytes.
It can support thousands of concurrent NFS connections.
Data is stored across multiple AZ's within a Region.
The durability is still not published yet.
Unlike S3, EFS is a block-based storage. We can put files on EFS and share these files with multiple EC2 instances.
Like S3, EFS has Read After Write Consistency.
Go to Storage, you can find EFS which is right below S3.
Some Region doesn't support EFS for now, for example, EU Region.
Go to create an EFS:
Configure file system access. Firstly, you need to select the VPC. You can use the default VPC for this region. Secondly, you need to Create Mount Targets. You can select which AZs you want to have mount targets in. You can select all AZs. And then you need to choose subnets. You can just choose the default subnets for this VPC. And then you need to choose Security Group. You can just choose the default security group for this VPC.
Add tags. Add tags for your EFS, which will help you to distinguish them easily in the future.
Review and Create. You will see your EFS is in one VPC, but across all three AZs and in three different subnets corresponding the three AZs. The security groups for these three parts of EFS are same. The IP address for these three parts of EFS will be automatically allocated.
Create three EC2 instances and put them into different AZs of the Region where you created the EFS, so you need to select corresponding subnets of the three parts of the EFS when you configure your EC2 instances.
Go to create a ELB. Configure the ELB and add the EC2 instances you just created into this ELB.
Go to EC2 instances, Action -> Network -> Change Security Group, select the security groups where your EFS are also in.
Now, you have 3 EC2 instances and they are in three AZs (also 3 subnets) of this region, and they are behind your ELB, and they are in same security group with your EFS. Your EFS are across 3 AZs (also 3 subnets) of this region.
SSH into these three EC2 instances, and go to root user. Install and start Apache httpd server for all of them.
Go to EFS console, click your EFS and in the File system access, click EC2 mount instructions. You will find the commands which can help you to mount your EC2 instances to EFS. Copy and paste the commands to your EC2 command line, and change sth at the end of the command, because you want to mount to /var/www/html directory, instead of the root directory. For example, the command could be "sudo mount -t nfs4 $(curl -s /var/www/html"
Now, the /var/www/html directory of your EC2 instances has been mounted to your EFS.
Create healthcheck.html and index.html in this directory of one of the instances, and these files will be automatically shown in other two instances, because they are all mounted in a same EFS. So you only have one copy of the code/files, but they can also be served through other instances.
Now, you can see the index.html through the DNS name of your ELB in browser. Thus, with EFS, you don't need mulitple copies of your codes, you don't need to mess around with bash scripts that all put your code down from S3 to your provisioned EC2 instances. You can actually have your code in one centralized repository, and then you can have EC2 instances that auto-scaled and then mount that EFS mount point as the root directory for Apache httpd server, so this save you a lot of time.
You need to know the use cases of EFS. We essentially use it as a file server. You store your files there, you make a centralized repository cross your EC2 instances. You can have multiple EC2 instances connect to the same EFS volume, and all accessing same copy of files. You can also apply EFS user level permissions, directory level permissions and file level permissions, you can make directories restricted in EFS and that restriction would be universal across all EC2 instances. With these restrictions, only specific users can access the files or directories in your EFS. EFS allows mulitple EC2 instances to connect/mount with it, so this is the most importance difference of it with EBS.