Moodle on AWS

AWS Terminology

  • EC2: Elastic Compute Cloud - the server where your code runs
  • EBS: Elastic Block Store - persistent block storage for EC2 instances
  • S3: Simple Storage Service - cloud & internet storage service (not directly linked to an EC2 instance)
  • Cloudfront:CDN (Content Distribution Network) service
  • Route 53: DNS services, including domain name registration
  • SES: Simple Email Service - for outbound email
  • VPC: Virtual Private Cloud
  • Elasticache: in-memory cache service (can be used for memcached, apparently)
  • AMI: Amazon Machine Image - is used to instantiate an EC2 instance
  • Elastic Beanstalk - automated scaling (auto-scaling & load balancing); abstraction layer on top of all the other AWS services. Official definition: AWS Application Container.
  • Region: geographical area where Amazon's datacenters are located
  • Availability zone: isolated location inside a region; this is where your EC2 instance lives
  • Amazon DynamoDB: NoSQL database service; can be used for session storage, apparently

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:

  • S3 and s3sf for files (use s3sf to symlink to filedir and lang directory)
  • AMI with Moodle's codebase
  • Elasticache for memcached caching (be careful: be default, Amazon selects one the most expensive caches for you!)
  • RDS for Moodle's MySQL database
  • Sessions can be handled by database

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

  • sudo useradd yoursuperuser
  • sudo usermod -a -G sudo yoursuperuser
  • sudo passwd yoursuperuser

Personal Tools