Use Amazon EFS with Amazon EC2
Amazon EFS provides scalable file storage for use with Amazon EC2. You can use an EFS file system as
a common data source for workloads and applications running on multiple instances. For more
information, see the Amazon Elastic File System product page.
For a tutorial on how to create a file system using the Amazon EFS console, see Getting started with
Amazon Elastic File System in the Amazon Elastic File System User Guide.
Amazon EFS is not supported on Windows instances.
Create an EFS file system using Amazon EFS Quick Create
You can create an EFS file system and mount it to your instance when you launch your
instance using the Amazon EFS Quick Create feature of the Amazon EC2 launch instance wizard.
When you create an EFS file system using EFS Quick Create, the file system is created with the
following service recommended settings:
-
Automatic backups turned on. For more information, see Using AWS Backup to back up and restore
Amazon EFS file systems in the Amazon Elastic File System User Guide.
-
Mount targets in each default subnet in the selected VPC, using the VPC's default
security group. For more information, see Managing file system network
accessibility in the Amazon Elastic File System User Guide.
-
General Purpose performance mode. For more information, see Performance
modes in the Amazon Elastic File System User Guide.
-
Bursting throughput mode. For more information, see Throughput
modes in the Amazon Elastic File System User Guide.
-
Encryption of data at rest enabled using your default key for Amazon EFS
(aws/elasticfilesystem
). For more information, see Encrypting
data at rest in the Amazon Elastic File System User Guide.
-
Amazon EFS lifecycle management enabled with a 30-day policy. For more information, see
Amazon EFS lifecycle
management in the Amazon Elastic File System User Guide.
- New console
-
To create an EFS file system using Amazon EFS Quick Create
Open the Amazon EC2 console at
https://console.aws.amazon.com/ec2/.
-
Choose Launch instance.
-
(Optional) Under Name and tags, for
Name, enter a name to identify your
instance.
-
Under Application and OS Images (Amazon Machine
Image), choose a Linux operating system, and then for
Amazon Machine Image (AMI), select a Linux
AMI.
-
Under Instance type, for Instance
type, select an instance type or keep the
default.
-
Under Key pair (login), for Key
pair name, choose an existing key pair or create a
new one.
-
Under Network settings, choose
Edit (at right), and then for
Subnet, select a subnet.
You must select a subnet before you can add an EFS file
system.
-
Under Configure storage, choose
Edit (at bottom right), and then do the
following:
-
Make sure that EFS is
selected.
-
Choose Add shared file system.
If Add shared file system is not
visible, you must first select a subnet.
-
For File system, select an existing
file system, or choose Create new shared file
system and create a file system using Amazon EFS
Quick Create.
-
For Mount point, specify a mount
point or keep the default.
-
To enable access to the file system, select
Automatically create and attach security
groups. By selecting this check box, the
necessary security groups will automatically be created and
attached to the instance and the mount targets of the file
system, as follows:
-
Instance security group – Includes an
outbound rule that allows traffic over the NFS 2049
port, but includes no inbound rules.
-
File system mount targets security group –
Includes an inbound rule that allows traffic over
the NFS 2049 port from the instance security group
(described above), and an outbound rule that allows
traffic over the NFS 2049 port.
You can choose to manually create and attach the security
groups. If you want to manually create and attach the
security groups, clear Automatically create and
attach the required security groups.
-
To automatically mount the shared file system when the
instance launches, select Automatically mount
shared file system by attaching required user data
script. To view the user data that is
automatically generated, expand Advanced
details, and scroll down to User
data.
If you added user data before selecting this check
box, the original user data is overwritten by the user
data that is automatically generated.
-
Configure any other instance configuration settings as
needed.
-
In the Summary panel, review your
instance configuration, and then choose Launch
instance. For more information, see Launch an instance using the new launch
instance wizard
- Old console
-
To create an EFS file system using Amazon EFS Quick Create
Open the Amazon EC2 console at
https://console.aws.amazon.com/ec2/.
-
Choose Launch Instance.
-
On the Choose an AMI page, choose a Linux AMI.
-
On the Choose an Instance Type page, select an instance type and then
choose Next: Configure Instance Details.
-
On the Configure Instance Details page, for File systems,
choose Create new file system, enter a name for the new file system,
and then choose Create.
To enable access to the file system, the following security groups are automatically created and attached
to the instance and the mount targets of the file system.
-
Instance security group—Includes no inbound rules
and an outbound rule that allows traffic over the NFS 2049 port.
-
File system mount targets security group—Includes an
inbound rule that allows traffic over the NFS 2049 port from the
instance security group (described above), and an outbound rule that
allows traffic over the NFS 2049 port.
You can also choose to manually create and attach the security groups. To do this, clear
Automatically create and attach the required security groups.
Configure the remaining settings as needed and choose Next: Add Storage.
-
On the Add Storage page, make any necessary changes, and then
choose Next: Add Tags.
-
On the Add Tags page, specify any tags if necessary, and then
choose Next: Configure Security Group.
-
On the Configure Security Group page, review the security groups
and then choose Review and Launch.
-
On the Review Instance Launch page, review the settings, and then
choose Launch to choose a key pair and to launch your
instance.
Test the EFS file system
You can connect to your instance and verify that the file system is mounted to the
directory that you specified (for example, /mnt/efs).
To verify that the file system is mounted
-
Connect to your instance. For more information, see Connect to your Linux instance.
-
From the terminal window for the instance, run the df -T command to
verify that the EFS file system is mounted.
$
df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/xvda1 ext4 8123812 1949800 6073764 25% /
devtmpfs devtmpfs 4078468 56 4078412 1% /dev
tmpfs tmpfs 4089312 0 4089312 0% /dev/shm
efs-dns
nfs4 9007199254740992 0 9007199254740992 0% /mnt/efs
Note that the name of the file system, shown in the example output as
efs-dns
, has the following form.
file-system-id
.efs.aws-region
.amazonaws.com:/
-
(Optional) Create a file in the file system from the instance, and then verify that
you can view the file from another instance.
-
From the instance, run the following command to create the file.
$
sudo touch /mnt/efs
/test-file.txt
-
From the other instance, run the following command to view the file.
$
ls /mnt/efs
test-file.txt
Delete the EFS file system
If you no longer need your file system, you can delete it.
To delete the file system
-
Open the Amazon Elastic File System console at
https://console.aws.amazon.com/efs/.
-
Select the file system to delete.
-
Choose Actions, Delete file
system.
-
When prompted for confirmation, enter the file system ID and choose
Delete file system.