Cloud Services / Serverless / Storage / Technology

Tutorial: Configure and Mount an EFS File System in Amazon EC2 Instance

3 Nov 2020 9:21am, by

In this tutorial, I will walk you through the steps involved in creating an Amazon EFS file system and mounting it in an EC2 instance. This article is a part of the series on making AWS Lambda functions stateful with Amazon EFS.

Create an Amazon EFS File System

Start by accessing the EFS section of the AWS Management Console. Click on the Create file system button to create the file system. Choose one of the VPCs from the dropdown. I suggest that you select the default VPC available in the chosen region.

Once the file system is created, click on the Access points tab to create an access point for our machine learning application.

Ensure that the root directory is /ml. It is more helpful to create a well-known root directory than the default option.

Configure the User ID and Group ID of POSIX user and root user as 1001. This is used in managing the and ownership and permissions of the file system.

Let’s have 777 as permission for the root directory path.

Finally, click on Create access point to finish the configuration.

Choose the Network tab to verify the availability of the EFS file system in all the subnets of the VPC.

The EFS file system is now ready. In the next step, we will access this from an Amazon EC2 instance.

Mount the EFS File System in Amazon EC2 Instance

In the first step of the EC2 launch wizard, choose the 64-bit Amazon Linux 2 AMI.

In the next step, choose t2.medium instance type.

In the third step, click on Add file system and choose the EFS created for this tutorial. Notice that the wizard has added the user data to mount the file system.

In the sixth step, choose the default security group along with a custom security group that has ports 22 and 5000 open. This configuration will let us SSH into the instance and also access the inference endpoint which will be exposed by the Python application.

Review and launch the instance.

Once the instance is in running mode, SSH into it to check if the EFS file system is mounted.

You should see the directory /mnt/efs/fs1/ which represents the same EFS file system that we created.

In the next part of this series, we will install PyTorch in the shared file system and run an inference service to test the environment. Stay tuned.

Janakiram MSV’s Webinar series, “Machine Intelligence and Modern Infrastructure (MI2)” offers informative and insightful sessions covering cutting-edge technologies. Sign up for the upcoming MI2 webinar at http://mi2.live.

Amazon Web Services is a sponsor of The New Stack.

Feature image by Martin Adams on Unsplash.

A newsletter digest of the week’s most important stories & analyses.