I’m working on a Drupal application, which is planned to be hosted in Amazon Elastic Beanstalk environment. Basically, Elastic Beanstalk enables the application to scale automatically by starting additional web server instances based on predefined rules. The shared database is running on an Amazon RDS instance, which all instances can access properly. The problem is the shared files folder (sites/default/files).
We’re using git as SCM, and with it we’re able to deploy new versions by executing
$ git aws.push. In the background Elastic Beanstalk automatically deletes (
$ rm -rf) the current codebase from all servers running in the environment, and deploys the new version.
The plan was to use S3 (s3fs) for shared files in the staging environment, and NFS in the production environment. We’ve managed to set up the environment to the extent where the shared files folder is mounted after a reboot properly. But…
The Problem is that, in this setup, the deployment of new versions on running instances fail because
$ rm -rf can’t remove the mounted directory, and as result, the entire environment goes down and we need restart the environment, which isn’t really an elegant solution.
Question #1 is that what would be the proper way to manage shared files in this kind of deployment? Are you running such an environment? How did you solve the problem?
By looking at Elastic Beanstalk Hostmanager code (Ruby) there seems be a way to hook our functionality (unmount if mounted in pre-deploy and mount in post-deploy) into Hostmanager (/opt/hostmanager/srv/lib/elasticbeanstalk/hostmanager/applications/phpapplication.rb) but the scripts defined in the file (i.e. /tmp/php_post_deploy_app.sh) don’t seem to be working. That might be because our Ruby skills are non-existent.
Question #2 is that did you manage to hook your functionality in Hostmanager in a portable way (i.e. by not changing the core Hostmanager files)?
Have you considered using
.ebextensions with your shared files stored in S3?
I have used
sources to deploy shared files (sitemaps) that are built by our app server (and stored in S3).
sources: "c:/inetpub/sitemaps": http://[S3 bucket]/sitemaps.zip container_commands: 01-copy-sitemaps-to-www: command: copy c:\inetpub\sitemaps\*.* c:\inetpub\wwwroot\ > copy_sitemaps_to_www.log 2>&1 waitAfterCompletion: 5
S3fs is a bad idea, performance-wise, and also S3 is not designed to be mounted, it’s not a filesystem, it’s an object storage.
Use EFS instead -> https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/services-efs.html
You will see in the documentation that there is a procedure for Drupal in Beanstalk.