Set up a static website on AWS using S3, Route 53, CloudFront, and Certificate Manager
Here, we’ll set up a static website (think HTML and CSS and no moving parts) hosted on S3, which can be accessed by your own domain, domain.com, protected with SSL (think https:// instead of http://).
Anyone who types in domain.com on their browser will be forwarded to https://www.domain.com so that you can have that fancy “Your connection is secure” lock!
If you are completely new to AWS, I recommend you take a look at the Intro to AWS for Newbies eBook before you embark on this. If you just want to figure out how to create that static website, read on!
We will go over setting up the website where the domain name is registered through Route 53 and where it’s registered using a 3rd party registrar like Namecheap.
Setting up Website with domain registered at Route 53
Purchase domain in question using Route 53
- Go to Route 53 and purchase a new domain for $12 by following the prompts
- If you are purchasing your domain from another registrar, go to “Setting up Website with External Domain Registrar,” complete the steps, and come back
Request SSL certificate from AWS Certificate Manager (ACM)
- Go to AWS Certificate Manager (ACM) and request a certificate for www.domain.com
- Include domain.com as another domain to protect with the same certification
- Select DNS Validation and validate via “Create record in Route 53“
- Confirm after 30 minutes or so that validation was completed
Create the website in S3
- Go into S3 and create 2 buckets: domain.com and www.domain.com
- Set domain.com S3 bucket to redirect to www.domain.com
- The website will be hosted in the www.domain.com S3 bucket
- In the www.domain.com bucket, set Bucket Policy to THIS:
Here’s AWS’s documentation on how this would work: Setting up a Static Website using Custom Domain
Create a new CloudFront Distribution
- Go to CloudFront and create a new distribution
- Get the Endpoint URL from S3 as Origin Domain Name instead of the bucket from the dropdown menu
- Set the SSL cert to the certificate just verified with ACM
- This will also take a while to go through
Here’s AWS’s documentation on how to create this distribution: Speed Up Your Website with Amazon CloudFront
Create A records in Route 53
Go back to Route 53 and create A Records to point to the new CloudFront distribution.
- Create A record for domain.com and point it to the S3 bucket for domain.com
- Create A record for www.domain.com and point it to the www.website.com CloudFront distribution you just created
- Both can be found in the dropdown under “alias”
Here’s AWS’s documentation on how this works: Using Route 53 for DNS
Setting up Website with External Domain Registrar
Sometimes, the domain extension is not a TLD supported by AWS, so we register using 3rd party like Namecheap. Or you just bought your domain at another registrar, and don’t want to transfer it over to AWS because it’s cheaper.
- Purchase domain in question at the 3rd party registrar
- Go to Route 53 and create a new Hosted Zone for domain.com
- Copy over the Name Server (NS) values (there are 4 of them) from Route 53’s Hosted Zone into the domain registrar’s DNS server settings
- Go back up to the previous section and pick back up at “Request SSL Certificate from ACM“
And that’s it! You can replace the S3 with an EC2 instance, and create the same set up for WordPress if you’d like!
Here’s a tutorial on how you can create a WordPress site on EC2: How to set up a WordPress site on EC2