Category: Moodle

Setting Up Moodle with AWS cloudfront CDN

before writting further , following is my exisitng architecture , where

  • ALB and ec2 are being utilized for Compute
  • RDS for database
  • EFS for moodledata
  • Redis for cache

Moodle version is 3.8

My Domain is pointing to Loadbalancer and site is being served.

Now , My Objective is to deliver the site utilizing AWS Cloudront CDN.

Setting Up Cloudfront :-

just navigate to aws cloud front service and start creating a distribution. you will find a web form to fill following sections.

  • Origin Setting
  • Cache Setting
  • Distribution Setting

Origin Setting:-

origin setting
  • Origin Domain Name : Select the ALB or ec2 on which the application is setup. It is the only thing which is requried.
    • origin path : Put the path if your site is runing in a directory or you just want to deliver the defined directory content, otherwise leave it blank.

Cache Settings :-

Cache Settings
  • Viewer Protocol policy is main thing to handle and it will depend upon the bhaviour of moodle implementation\
    • whether your site is using ssl
    • if you are enforcing https to user
    • if loadbalancer is utilized to offload ssl

as we force https, so in my case, i have set it up to HTTPS only

Distribution Settings:-

Distribution Settings
  • If site is using https then you need to import certificate through AWS ACM service, then it will be available for selection
  • Cloud front will provide a unique domain name , <d3e5asd3gad9wckaz> If you want to use your own domain, you can put that domian under CNAME. so that, the same will be accessible by your domain as well.
  • you can put logs into s3 bucket, loggin and log prefix is optional
Final Architecutre

So we are done with setting up. It will take few minutes to deploy. Once it is deployed, you can try accesssing with the CNAME, and moodle should be served through cloudfront.


  • here we are delivering the complete site with cloudfront
  • only GET Request are cached, POST and other actions are forwarded directly
  • one can control caching behaviour by various ways
    • header values
    • apache mod header setting and values
    • maximum time to cache
  • one can put pre and post hook to execute , means, you can manipulate request , before it reaches to the web server and response, before it is reached to end user by invoking Lambda.
Pros :-
  • You can utilize best of CDN to deliver the content, it will help to imprvoe performance by caching , more control on each request, end user will get the speed as it content is being delivered from nearest location

Note :- Origin Response Timeout can be maximum set to 60 seconds. Although there should not be any process which takes more than that, ,but heavy process which are processed on demand or report downloads can lead to 504 timeout. The same condition is with ALB, but we can increase that beyond 60 seconds.

Setting up Airnotifier Push notification in Customized Moodle Mobile App

Considering that, we are building the mobile app from moodle app codebase. we will be setting up

Environment Specs-

app release version github tag :

airtnotifier version : 3

server environment : ubuntu

moodle version : 3.8

Airnotfier Setup :-

it requires python, so check the python version.

 >>> python --version

# make a directory to check the airnotifier from git, so lets say you are at home directory
>>> cd ~

## check out source code
>>> git clone -b master git:// 

# install python3 build tools
>>> apt-get install python3-pip build-essential git

# into checked out code directory
>>> cd airnotifier 

# setup python3 env
>>> pip3 install pipenv --user

# in my case, python3 was available with command python3
>>>  python3 -m pipenv install --deploy
>>> cp

# there is nothing to change as sample has everything. 
# it will require mongo db in order to run, if you do not have 
>>> echo "deb buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
 >>> sudo apt-get update
 >>> sudo apt-get install -y mongodb-org
 >>>  sudo apt-get install -y mongodb-org
 >>>  sudo systemctl start mongod
 >>>  sudo systemctl status mongod

# install airnotifier
>>> python3 -m pipenv run ./
>>> python3 -m  pipenv run ./

Imp-1 : make sure the port mentioned in /8801 is accessible from outside world , if not check ufw or firewall setting to allow port

Imp-2 : In order to run this without interrruptinng, you can utilize screen so that it run’s on virtual terminal that does not end after your session.

you can try accessing : In your browser: http://your_server_ip_address:8801 – Login as [email protected]/admin

Airtnoifier Screen

Create an app with the package name :-

Now , you need to do few more setup in regards of usage and that will depend upon the app type

Mobile App Configuration

1- Android App Configuration :-

  • In order to use this on Android Platform, you need to create a project in firebase.
  • Create a project and go to project settings
  • create an android app there and download google-service.json
  • Put that google-service.json in ionic moodle app codebase at root location [there are other files like config.xml, package.json etc]
  • Copy the project Id from Firebase Console project settings
  • put it under airnotifer “Firebase Cloud Messaging settings” section, project id and content of google-service.json

Now it is to setup the Moodle Codebase so that Notification can be pushed to Airnotifier.

1- IOs App Configuration :-

  • Key ID : <you can create and it will be available >
  • Key File [p8 content]:

Imp- IOs notification can not be tested on Emulator.

Setup Moodle in order to user Airnotifier :-

  • under <moodleurl>/admin/message.php or Site administration > Messaging > Notification settings , enable Mobile Notification.
  • Click on Settings , and put the requried detail
    • Airtnotifier url, port number, package, airtnoifier app name [can be copied for airnotifier], Access key [ you can create that from air notifier app section]

So the setup part is done.

Important Points And How to Debug

Important Points :-

1- as this has custom package name, so please make sure you have changed this under Site administration > Mobile app > Mobile appearance Android app’s unique identifier section in moodle codebase

2- Android Notification can be tested on virtual device as well.

3: If your app crashes on receving notification while app is open

  • go to file message/output/airnotifier/message_output_airnotifier.php
  • edit file and go to line number 125, put the following code
    • unset($extra->notification);
$curl->setopt(array('CURLOPT_TIMEOUT' => 2, 'CURLOPT_CONNECTTIMEOUT' => 2));
// put the follwing line after above lines

How to Debug :-

  • As soon as you launch app , Server will register this. check the token from mdl_user_devices table
  • jsut try to send a message from admin to your app user from moodle interface and check in airtnotifer > <your app> > logs section.

if you get this , it means your moodle is communicating with Airnotifier Server. If not , it means there is problem as moodle is not able to push the message to airnotifer. jsut recheck moodle airnotifer setting again.