Table of Contents

Moodle on AWS

AWS (Amazon Web Services) promises high scalability, globally distributable web applications. There are some examples of Moodle installations on AWS. Here are a few resources:

AWS Terminology

Beanstalk Solution for Moodle

Moodle consists of a php codebase (all the php scripts making up the application), a database, user files and sessions. In addition, Moodle uses caching to speed up things. To provide a scalable hosting solution for Moodle using AWS, we need the following components:

Custom Beanstalk AMI

Beanstalk offers auto-scaling & load balancing right out of the box. But the EC2 instance is based on a default Amazon-linux AMI, which does not suit my purposes very well. I want to use an Ubuntu box, so to speak.

To use your own AMI, you first need to create one, in the EC2 part of the AWS Dashboard. Then, back in the Beanstalk part of the Dashboard, you can put in the id of your AMI. - Select your region (note: Frankfurt currently does not support Elasticache, so choose Ireland if you're in Europe - we're gonna need Elasticache for session storage) - In the EC2 dashboard, pick a hvm type of virtual server (see Amazon's Virtualization Types, which explains this provides better performance). - Create and launch the instance

Apparently, it's next to impossible to use an AMI that was not created with Beanstalk. The only option is to customize an existing Beanstalk AMI, by launching it as a new EC2 instance…

Anyway, Amazon's Beanstalk AMIs are pretty well configured. I found that all prerequisites for Moodle were met from the very start.

Deploy Moodle Codebase: Remove composer.json

If you are deploying your application to AWS Elastic Beanstalk, and you have a composer.json file in the root of your package, then Elastic Beanstalk will automatically perform a Composer install when you deploy your application. So, remove or rename the composer.json file before you upload your Moodle codebase to Beanstalk.

To properly use composer.json, consult this article: Composer on Elastic Beanstalk

Install Fuse s3fs

Excellent tutorial: How to mount an Amazon S3 Bucket on an Amazon EC2 Instance by using FUSE and S3fs (as a Moodle data directory)

See also: InstallationNotes On a running EC3 instance:

  1. sudo yum install libstdc++-devel
  2. sudo yum install fuse
  3. sudo yum install fuse-devel
  4. cd /src
  5. unzip master.zip
  6. cd s3fs-fuse-master
  7. ./autogen.sh
  8. ./configure –prefix=/usr
  9. make
  10. sudo make install

Then specify your Security Credentials (Access Key ID & Secret Access Key) in /etc/passwd-s3fs, using accessKeyId:secretAccessKey. Apparently, you also need to do: sudo chmod 640 /etc/passwd-s3fs.

Now mount the s3 bucket:

mkdir -p /mnt/s3
s3fs mybucket /mnt/s3 -o allow_other

Finally, symlink your moodledata directory to S3:

cd /mnt/s3-drive
sudo mkdir moodledata
cd /var/www/html
sudo ln -s /mnt/s3-drive/moodledata .
sudo chmod 777 -R moodledata

OPEN QUESTION: How do you make sure that the configuration changes are applied to all EC instances? Is there a way to create a new AMI out of the modified EC instance and use that to spawn new EC instances?

Unmount

sudo fusermount -u /mnt/s3-drive

Attention: the directory will still be there, so don't get confused if you still see s3-drive in your directory listing.

Add A Superuser