S3 Hosting

While preparing for my exams I had purchased this domain – dangilpin.click – to use during the labs for S3, Route 53, and CloudFront, etc. At that time I also had three existing web sites running on traditional hosts. I kept this domain to repurpose as a portfolio site, and have transferred the other three domains to AWS. I was thinking some content would have to go due to not having PHP anymore. But as it turns out that Google maps and analytics, and my contact forms all used javascript and remote servers to function – so those work without modification!

The only thing I had to leave behind was a php mySQL time-tracking app that I didn’t use anymore anyway (iPhone apps do it better now). I will save that as a good serverless project!

Now I have four sites served serverless-style via AWS! I was spending on the order of $200 per year for hosting fees. Now I will only spend about $30!

There are a few things to do yet:

  • get the www requests to go to the apex/naked domain name
  • get SSL certs for https requests
  • add dynamic content via Lambda and API Gateway
  • replicate wordpress-like functionality using S3
  • maybe an IOT project or two

CloudFront CDN and SSL Certs

Amazon provides free, managed certificates for https requests – even for static hosting on S3! Sounds great, so I start to implement that for my sites hosted by S3 only to find that it requires AWS CloudFront to be in front of your hosting. That is a little more involved and costly that I wanted, but I continued anyway just for the experience.

I deployed four CloudFront distributions – one for each domain – and reconfigured Route 53 to point to the CDN’s instead of the S3 hosted sites.

A new problem cropped up: default files such as index.html would return 404 errors! After some searching I realized that the standard way of setting an S3 bucket as the CDN’s origin meant that all url’s would have to include the “index.html”. The solution was to keep S3 hosting turned on and make the S3 hosting – not the bucket itself – the origin for the CDN’s. This was not obvious while configuring the CDN’s because the origin fields in the console would not populate with the hosted sites ARN’s! I had to copy the ARN from S3 and paste them into the origin fields!

CloudFront has an option to redirect http requests to https to use the certificate. That is what my sites use now.

On a related note, you must also delete whatever is in the “Default Root Object” field. And finally enter all domains – dangilpin.click AND www.dangilpin.click – into the “Alternate Domain Names” field.

Now I have SSL working on each site, with the added CDN performance boost. CloudFront (US, Canada, EU only) is only a few pennies due to the low traffic – not sure what that cost is for a commercial application, but probably pretty low if it is like most AWS services.