AWS Static Site Memorandum
Below is a simple memorandum on setting up this static website and running it in AWS as I wanted it. Mostly, so that I'll be able to recall what the heck I did to get it all done. The fun thing about AWS documentation and tutorials is that there is an abundance of content available, but they all seem to tragically be missing that one crucial bit of information you need. This post will be yet another statistic in evidence to that fact. ๐ So, to achieve victory in this effort, you just need to get gather a good full handful of them and then put all the pieces together.
Note that the outcome I was working towards was that the site was referenced canonically only at the naked domain
corthulhu.com
, and that the www
subdomain variant was just always redirected there.
Additionally, the web stack I was targeting was simply:
- S3 bucket(s) for the file/object store
- CloudFront (referencing the S3 objects) for content distribution
- Whatever else is necessary for achieving #1 and #2
Domain Certificate via AWS Certificate Managerโ
I only ran into one snag setting up the cert I needed for SSL on this domain. To get going, you just need to populate the CNAME values in your domain registrar's DNS with those that AWS provides you. Then, just wait for that AWS validation to complete.
The snag I hit was that since CloudFront effectively operates in the Global region, the convention they have set up
is that you need to have your certificate(s) in the us-east-1
(N. Virginia) region. I initially had spun mine up in
the us-east-2
region (which is where all of my other services are located), and had to unwind to get around this roadblock.
Point DNS to Route 53โ
My domain is registered at NameSilo. There are some limitations there for pointing to things like CloudFront
distributions. To centralize and make things a bit easier, I ended up pointing the domain's Name Servers to AWS Route 53.
To do so, I simply set up a public hosted zone for corthulhu.com
, and matched the NameSilo Name Server collection to those
four defined by Route 53. Now I did/can do all the DNS shenanigans necessary in Route 53.
Although as-is I got everything working as desired, I may ultimately end up moving the registration over to Route 53 for added convenience.
S3 Bucket Setupโ
To handle the primary naked domain with www.
subdomain handling, I utilized two buckets (w/primary notes) as follows:
Bucket for naked domain (corethulhu.com
):
- Contains all the website's objects in the root of the bucket
- This bucket is set up as the primary content handing bucket to point at from CloudFront; notes below;
- Block all public access = on; bucket policy = JSON object w/allow get object for CloudFront distribution ARN; static website hosting = disabled
Bucket for www
subdomain (www.corethulhu.com
):
- Contains no objects
- This bucket is simply set up as static website hosting redirect; details below:
- static website hosting = enable; hosting type = redirect requests; hostname =
corethulhu.com
; protocol = https
- static website hosting = enable; hosting type = redirect requests; hostname =
A notice. When setting up an S3 bucket for static site hosting, you are greeted with a recommendation (read advertisement) to use AWS Amplify Hosting instead. I looked into going down that route a bit but for simple setups such as this, I feel that attempting the shortcut . :possibly_sus:
CloudFront Setupโ
And there you have it. You're welcome future Corey Rosemurgy.