Elastic Beanstalk deletes EFS mountpoint during deployment

Post date: Mar 19, 2017 6:00:15 PM

I like aws elastic beanstalk to deploy high availability and scalable php applications without worrying about the underlying server operations. Recently I was a testing EFS for zend application, here is the sample directory structure of Zend Framework 3 app:

config

vendor

public

module

data

As I wanted to share the `data` directory between EC2 instances, I thought to try EFS to share `data` folder between instances and so i created a EFS outside of beanstalk and used .ebextensions to mount the by providing the ID in the config script.

After the first deployment, everything went smooth. But after 2nd and 3rd deployed, I noticed an error in application and to my surprise the data directory was empty, even though it was showing as mountpoint.

I thought may be the EFS was not mounted properly or EFS is having downtime, after checking everything, I concluded that EFS is indeed empty, and now the question is how?

After doing few sample deployments I found out that the Elastic beanstalk during deployment deletes everything in the whole /var/app/current directory and copies the new application code, which indeed deletes the data folder, which is a mountpoint of EFS.

I think elastic beanstalk should use CodeDeploy to deploy the app which would have given error during deployment if a non versioned file is found, rather then deleting all files and copying. Otherwise I am not sure how EFS can be used in elasticbeanstalk unless you are mounting the directory outside of /var/app/current, because `eb deploy` will delete the all content of data directory everytime.

Thankfully i was working on dev environment and only lost of about few Mbs of application's data files.