Drupal with S3 on Elastic Beanstalk - AWS

This tutorial uses S3FS-FUSE and AWS Elastic Beanstalk for persistent storage across EC2 instances.

Drupal with S3 on Elastic Beanstalk - AWS

Drupal with S3 on Elastic Beanstalk - AWS

This tutorial uses S3FS-FUSE and AWS Elastic Beanstalk to make sure that your Drupal installation, after each deployment, connects to your S3 storage and uploads all static content (such as images) right there.

This tutorial is based on Matt Zuba's post <s3fs-fuse and AWS Elastic Beanstalk> in which he connected Wordpress with S3, which of course we tweaked it a bit to suit our needs.

As Matt says, the obvious choice for centralized resource storage is AWS S3. The unobvious choice is how to go about it. We personally tried a few different extensions to suit our needs in Drupal (such as Amazon S3), but they always failed for some reason or another. What this configuration achieves, is it mounts an S3 bucket as a local folder on the file system. This seemed like the perfect solution.

You'll find below the config file. Simply add an Access Key to your Elastic Beanstalk configuration (one that has access to the bucket you’re referencing), replace the bracketed options with your specific Access Key, Secret Key and AWS Bucket name; make sure your Drupal configuration saves the files in \sites\default\files\s3 and drop this file into your .ebextensions folder. All you have to do afterwards is just deploy it to your Beanstalk environment.

PS: We had big problems saying that "s3fs: could not determine how to establish security credentials.". We fixed it by simply rendering another access key/secret (and another, and another, and another...) until AWS gave us one without ANY symbols. That one finally worked :-)

``` packages: yum: unzip: [] git: [] gcc: [] libstdc++-devel: [] gcc-c++: [] fuse: [] fuse-devel: [] libcurl-devel: [] libxml2-devel: [] openssl-devel: [] mailcap: [] automake: [] files: "/tmp/master.zip": source: https://github.com/s3fs-fuse/s3fs-fuse/archive/master.zip "/etc/fuse.conf": mode: "000644" owner: root group: root content: | # mount max = 1000 user_allow_other "/etc/passwd-s3fs": mode: "000600" owner: root group: root content: | # set AWS cred as global AWS_KEY:AWS_SECRET "/opt/elasticbeanstalk/hooks/appdeploy/pre/11_unmount_s3fs.sh": mode: "000755" owner: root group: root content: | #!/usr/bin/env bash if mountpoint -q /var/www/html/sites/default/files/s3; then fusermount -u /var/www/html/sites/default/files/s3 fi "/opt/elasticbeanstalk/hooks/appdeploy/enact/02_mount_s3fs.sh": mode: "000755" owner: root group: root content: | #!/usr/bin/env bash . /opt/elasticbeanstalk/support/envvars sudo mkdir -p /var/www/html/sites/default/files/s3 sudo chown webapp:webapp -R /var/www/html/sites/default/files/s3 uid=$(id -u webapp) gid=$(id -g webapp) s3fs AWS_BUCKET:/path/to/folder /var/www/html/sites/default/files/s3 -o nonempty -o uid=$uid -o gid=$gid -o use_cache=/tmp -o allow_other -o passwd_file=/etc/passwd-s3fs commands: 001_unzip_dir: cwd: /tmp command: "sudo unzip -o /tmp/master.zip -d /opt && rm -rf /tmp/master.zip" 02_install_s3fs: cwd: /opt/s3fs-fuse-master command: "./autogen.sh && ./configure --prefix=/usr && make && sudo make install" ```

Final notes

Need help implementing this?

Feel free to contact us using this form or via email at .

Share this on LinkedIn

More Articles

Our Certifications

AWS DevOps Engineer AWS Solutions Architect AWS SysOps Administrator Google Certified Administrator Microsoft Certified Professional
-->