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

Last updated: 2021-03-18

I want to mount an Amazon Elastic File System (Amazon EFS) volume to an 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 uploaded or modified by users of your application. Your application can treat a mounted Amazon EFS volume like local storage, so you don't have to change your application code to scale up to multiple instances.

To mount an Amazon EFS volume to an Amazon Elastic Compute Cloud (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 to allow inbound connections on port 2049 (Network File System, or NFS) from the security group associated with the 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: If you're mounting the mount targets of one subnet on an environment in a different subnet, then the Amazon EFS security group 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 EC2 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