In this article, I am going to show you how to create a new Amazon Elastic File System (Amazon EFS) file system, then mount it to a new Amazon Elastic Compute Cloud (Amazon EC2) instance using the EC2 Launch Instance Wizard, verify that file system is mounted on the EC2 instance, and then delete the resources created.
Please visit my GitHub Repository for EC2/EFS articles on various topics being updated on constant basis.
Letβs get started!
Objectives:
1. Create the security groups - myec2-sg
, myefs-sg
2. Create the EFS file system - myefs
3. Launch the EC2 instance myec2
and mount the file system
4. Verify EFS file system is mounted
5. Cleanup
Pre-requisites:
- AWS user account with admin access, not a root account.
- AWS CLI.
Resources Used:
Launch Instance Wizard documentation
Steps for implementation to this project:
1. Create the security groups - myec2-sg
, myefs-sg
- Create two security groups in the default VPC, in
us-east-1
region
myec2-sg
This
myec2-sg
security group will be attached to the EC2 instance and it allows only SSH inbound connection to the EC2 instance and any outbound connectivity.on the left navigation pane, choose Security Groups
Create security group
myec2-sg
,default vpc
, choose the Inbound Rules tab, Add Rule, TypeSSH
, Port22
, CIDR block0.0.0.0/0
choose the Outbound Rules tab and verify that the Type is All traffic.
Create security group
myefs-sg
This
myefs-sg
security group will be attached to the EFS file system and allows only TCP connection on port 2409 from the EC2 instance and any outbound connectivity.on the left navigation pane, choose Security Groups
Create security group
myefs-sg
,default vpc
, choose the Inbound Rules tab, Add Rule, TypeNFS
, Port2049
, CIDR block choosemyec2-sg
choose the Outbound Rules tab and verify that the Type is All traffic.
Create security group
2. Create the EFS file system - myefs
Go to Amazon EFS in the AWS Management Console and choose Create file system.
myefs
, choose yourdefault VPC
.click
Customize
, you will see all the following default inputsNext,
In the Security groups column, see the existing security groups, in different subnets and Availability zones
Next, Next,
Review and create
Create
- Click the
myefs
file system , on network tab, in the Security groups column, you will see these following security groups.
- Delete all the existing security groups and add the
myefs-sg
security group.
Next, Next,
Review and create
Create
3. Launch the EC2 instance myec2
and mount the file system
On the Amazon EC2 console and choose Launch Instance.
Amazon Linux 2 AMI, t2.micro, NVirKey, default vpc, default-subnet-1a
, Select existing security group, choose theec2-sg
security groupConfigure storage, File systems, Edit
Share file system and select the file system ID of
myefs
from Step 2.See the mount path - this is the location at which the file system will be mounted on the EC2 instance.
You can customize this path, but I am keeping the default value.
Launch instance
Note: After you select the file system ID, the User data field is automatically populated with a configuration script that automates all manual tasks, such as installing the file system client, installing the EFS mount helper (for Amazon Linux only), and updating the EC2 instance properties so that the file system mounts automatically upon instance reboot.
4. Verify EFS file system is mounted
On the EC2 console, choose Instances, then select the EC2 instance
myec2
you created in Step 3.Choose Connect.
In the Connect to your instance dialog box, choose EC2 Instance Connect (browser-based SSH connection) and
then choose Connect.
In the EC2 instance CLI, type the following command:
df -T -h
You can see that the EFS File System is mounted at
mnt/efs/fs1
which is the same default mount path as seen in Step 3.This verifies that your file system
myefs
is successfully mounted on the EC2 instancemyec2
.
- Cleanup
Terminate EC2 instance -
myec2
Delete EFS file system -
myefs
Delete Security groups -
myec2-sg, myefs-sg
What we have done so far
We have successfully created a new Amazon EFS, then mounted it to an Amazon EC2 instance using the EC2 Launch Instance Wizard, verified that file system is mounted on the EC2 instance, and then deleted the resources created.
Top comments (0)