Drupal 9 - Static Hosting with AWS - Overview

By ReginaHack, 27 June, 2020
Drupal 9 - static website hosting with AWS S3

As I'm working on getting AWS certified, I'm always in need for a examples to play with new services. What better way to do it while also testing out the newest Drupal version?

Ever since I learned that one can host static websites on S3 I wanted to test it out, but I never had a good use- case. I also run a personal blog that was collecting so much dust it would have been a health hazard to even log-in to try and edit it. With a bit of time on my hands this weekend, I finally decided to just get started.

The Drupal setup is as follows:

Drupal9 with lando, tome and github

 

The .lando file after running 'lando init' looks like this:

name: NAME
recipe: drupal9
config:
  webroot: .
  php: '7.3'
  drush: "*"

The only tricky part here was that the database/user/pwd is not named 'drupal9', but still 'drupal8'.

To generate the static site all I have to do now is to run:

lando drush tome:static --uri=https://reginahack.com

After it is generated, I commit/push the changes to GitHub. AWS CodePipeline gets notified automatically via GitHub Webhooks and the static site gets upload to the S3 bucket.

CodePipeline-AWS Execution

To setup your S3 bucket with static website hosting, change the properties of the bucket. Don't forget to set the right policies otherwise you won't be able to access the site.

S3 Static hosting of drupal9 website

The Route 53 setup can get tricky as we need CloudFront for SSL using the Amazon Certificates. What we need to do is:

- add an A record pointing to the alias of our CloudFront distribution

- redirect www to the main domain

- get SSL certificates in US-East (otherwise CloudFront doesn't work)

- add the DNS verification entries to the hosted zone

In CloudFront the redirect http to https options needs to be switched on under 'behavior settings'.

CloudFront redirects

Any questions? Connect with me on Twitter or LinkedIn.