How can I mount an Amazon EFS volume to an instance in my Elastic Beanstalk environment?
Last updated: 2020-03-18
I want to mount an Amazon Elastic File System (Amazon EFS) volume to an instance in my AWS Elastic Beanstalk environment.
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 note the EFS ID and security group ID.
2. To allow connections, edit the security group rules of the EFS 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 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.
Note: The configuration file includes a script that adds an entry in the fstab (file system table) system configuration file, and mounts all (-a) file systems listed in the fstab file of type (-t) nfs4. The type is always nfs4 for Amazon EFS. The file systems listed in the fstab file are automatically mounted using the mount -a command 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: