Moodle is hosted on AWS cloud and the following AWS services are being used for this solution
- 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 AWS 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 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.
- Viewer Protocol policy is the main thing to handle and it will depend upon the behavior of moodle implementation\
- whether your site is using SSL
- if you are enforcing HTTPS to user
- if load balancer is utilized to offload SSL
as we force https, so in my case, I have set it up to HTTPS only
- If site is using https then you need to import a certificate through AWS ACM service, then it will be available for selection
- Cloud front will provide a unique domain name, <d3e5asd3gad9wckaz>.cloudfront.net. 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, logging and log prefix is optional
So we are done with setting up. It will take few minutes to deploy. Once it is deployed, you can try accessing 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 behavior 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 respond, before it is reached to end user by invoking Lambda.
- You can utilize best of CDN to deliver the content, it will help to improve performance by caching , more control on each request, end user will get the speed as it content is being delivered from the 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.