Amazon Elastic File System (Amazon EFS) provides a simple, scalable, fully managed elastic NFS file system for use with AWS Cloud services and on-premises resources. It is built to scale on demand to petabytes without disrupting applications, growing and shrinking automatically as you add and remove files, eliminating the need to provision and manage capacity to accommodate growth.

Amazon EFS offers two storage classes: the Standard storage class, and the Infrequent Access storage class (EFS IA). EFS IA provides price/performance that's cost-optimized for files not accessed every day.

In this lab, we going to create an EFS and test the file system between two instances.

Requirements

  • AWS Account
  1. In the AWS Management Console go to EFS

2. Click on Create file system

3. Give it a name, and click on Customize

4. Disable Automatic backups as this is for testing, and click on Next

5. In the next window leave it in defaults and click Next, is important to say that if you are using this for production, you need to create your own security groups here, don't use default security group.

6. in the File system policy leave at defaults and click Next

7. Review the settings and click on Create

8. If everything is correct you will see the Success message

9. Click on the Name of the NFS to enter to the Details on the Network Tab

You will see that the EFS have a security group for each subnet, we need to open the traffic for the instances, copy the securty group.

10. Go to EC2

11. Security Groups

12. Select the security group and click con Actions, Edit Inbound rules

13. Click on Add rule and we going to add the CIDR block of the VPC to permit all the traffic, if you are using this for production, is important to you use your own security groups and instead of use all the CIDR block use the instance security groups.

For production, is important to use your own security groups, as I for testing open all the CIDR block to the EFS, if you need to know more about security groups check my other posts.

14. Add a rule and select All traffic, and as source use your own CIDR block

15. Go back to EFS

16. Select the EFS and click on the name for enter to the details and click on Attach

17. Copy the command for the NFS Client

18. Now that the NFS is ready and we have the mount command, it's time launch the instances, go to EC2

19. Go to Instances

20. Click on Launch instances

21. Select the Amazon Linux 2 AMI

22. Select the t2.micro and click Next

23. In Configure Instance Details, select 1 instance, we want to test the EFS across AZ so in the Subnet I'm going to select for one us-east-2a and us-east-2b for the second instance, make sure you select Auto-assign Public IP with Enable, and click on Review and Launch

24. After review the configuration, click on Launch

25. Create a new key pair, give it a name, Download the Key Pair, and click on Launch instances

26. If everything is ok, you will see the Launch Status with a Success message, click on View Instances

27. Repeat the steps from 13, and launch a second instance with the same configuration, but in other Subnet (AZ) and Select a existing Key Pair and select the same for the first instance.

28. Now that we have the two instances running, lets connect to each one and test the EFS, Select the first instance anc click on Connect

29. Click and Connect and a window will open with the comand line.

30. Gain root permissions and create a directory where we going to mount the EFS system.

sudo su -
mkdir ~/efs-system

31. Install nfs-utils

yum -y install nfs-utils

31. Now mount the system with the command we copy earlier

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-2ba4d853.efs.us-east-2.amazonaws.com:/ ~/efs-system

32. Go to the EFS directory and lets create a file

cd ~/efs-system
touch demo.txt
echo "this is a demo file from instance 1" > demo.txt

33. Now connect to the second instance, select the instance and click on Connect

34. Gain root permissions and create a directory where we going to mount the EFS system.

sudo su -
mkdir ~/efs-system

35. Install nfs-utils

yum -y install nfs-utils

36. Now mount the system with the command we copy earlier

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-2ba4d853.efs.us-east-2.amazonaws.com:/ ~/efs-system

37. Go to the mount and check that we have the demo.txt file

cd ~/efs-system
ls
demo.txt

38. Use cat to see that the content is the same

cat demo.txt
this is a demo file from instance 1

Great with this you finish the lab! in the next post we going deeper into the AWS services.

Clean-Up

  1. Go to EFS

2. Select the EFS and click on Delete

3. Confirm

4. Go to EC2

5. Go to Instances

6. Select the instances we use for this lab, and click on Instance state then Terminate instance

7. Confirm

8. Go to Security Groups

9. Select the security groups we create on this lab, and click on Actions and then Delete security group

10. Confim

11. Click on the default security group

12. Click on Edit inbound rules

13. Delete the rule we add to permit all the traffic on the CIDR block (be carfull)

14. Save the rules

15. Go to Key Pairs

16. Select the Key Pair, we create in this lab and click on Actions then Delete

17. Confirm