How can I mount an Amazon EFS volume to an instance in my Elastic Beanstalk environment?

2 minute read

I want to mount an Amazon Elastic File System (Amazon EFS) volume to an Amazon Elastic Compute Cloud (Amazon EC2) instance in my AWS Elastic Beanstalk environment.

Short description

In an Elastic Beanstalk environment, you can use Amazon EFS to create a shared directory that stores files that are uploaded or modified by your application's users. Your application can treat a mounted Amazon EFS volume as local storage. Therefore, you don't have to change your application code to scale up to multiple instances.

To mount an Amazon EFS volume to an Amazon EC2 instance in your Elastic Beanstalk environment, you must include configuration files in your source code.


1.    Create an Amazon EFS file system, and then note the Amazon EFS ID and security group ID.

2.    To allow connections, edit the security group rules for the file system. The rules must allow inbound connections on port 2049 (Network File System or NFS) from the security group for instances in your Elastic Beanstalk environment.

3.    Update the instance security group to allow outbound connections on port 2049 to the Amazon EFS security group.

Note: The Amazon EFS security group must allow inbound connections when you mount the mount targets of one subnet on an environment in a different subnet. That is, it must allow inbound connections on port 2049 from your Amazon Virtual Private Cloud (Amazon VPC) CIDR.

4.    In the root of your application bundle, create a directory named .ebextensions.

5.    Add a formatted configuration file (YAML or JSON) to your directory.

Important: Add the file system ID in the configuration file. Replace FILE_SYSTEM_ID: {"Ref" : "FileSystem"} with FILE_SYSTEM_ID: fs-xxxxxxxx. The configuration file includes a script that mounts the Amazon EFS file system to the instance during deployment.

6.    Deploy the source code that includes the configuration file from step 5 to your Elastic Beanstalk application.

7.    To confirm that your Amazon EFS volume is mounted to your instance on your specified mount path, run the following command:

df -H

Related information

Mounting EFS file systems

Using Elastic Beanstalk with Amazon Elastic File System

Security in Amazon EFS

AWS OFFICIALUpdated a year ago