For over a decade I've bounced between GoDaddy and NameCheap for all my personal domain and web hosting needs. While those services are easy, they don't provide the scaling or performance to match my current 2019 use cases. As a result I've shifted to Amazon Web Services.
On AWS a basic static website can be created using two services: Route 53 and S3. And If we want a secure website we can enable https by including CloudFront into our configuration.
Low Cost. Cloud pricing can get extremely complex, but it ultimately is very low cost. On S3, each Gigabyte of storage costs approximately $0.023 cents per month.
Speed. Without getting into the nitty gritty of Regions and CDNs, for all intents and purposes serving files from S3 will be limited only by the user's network speed.
The major drawback of using S3 is it can only be used to host static websites and client side scripting. This means it can be used to host a React.js site, or Vue.js. But it cannot be used for Wordpress or any PHP or node.js code.
Prerequisites
If you're looking to make your website available at a custom domain name you'll have to purchase it first. That can be done through AWS or with any other domain registrar. However if it is purchased outside of AWS you'd need to point the NS records to a Route 53 hosted zone so your domain can be managed on AWS and used in the configuration below.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mysite.com/*"
}
]
}
Copy the Endpoint URL. We'll need it for the next section. It'll look like this:
http://mysite.com.s3-website-us-east-1.amazonaws.com
Now that we have an S3 bucket accessible by an Endpoint URL we need to make it accessible through our domain name, too.
Choose A Record and set the name to match your domain name.
Configure it as an Alias and set Alias Target to the S3 Endpoint. The name should appear in the drop down menu. If it doesn't, return to your S3 console and verify that the bucket name exactly matches the domain name. Save your record when done.
At this point we can now access our S3 bucket through our desired URL in a browser. However, this URL is only HTTP. If that's good enough, you can stop here. Otherwise we'll configure HTTPS in the next section.
Before we enter into CloudFront we want to create a new SSL certificate.
Press Request a certificate. If prompted, set the type as public certificate
Under Add domain names
enter your domain name. E.g.: mysite.com
When ready, press Next.
Choose your validation method. DNS validation is the preferred method. If you're controlling DNS through route 53 it gives an extra layer of convenience. When ready, Press Review then Confirm and request.
You'll be given a CNAME record which need to be inserted for verification. If you're using Route53, there's a convenient button to Create record in Route 53. Otherwise, open your DNS manager and add the Name and Value info manually.
Create a new distribution. Make sure the Delivery Method is set to Web before continuing. Set Origin Domain Name to the static website hosting URL for your S3 bucket. Do NOT select the S3 URL from the autogenerated dropdown list. The public S3 endpoint is needed if you want sub directories to resolve properly.
mysite.com.s3-website-us-east-1.amazonaws.com
Origin Path can be index.html. Scroll to Distribution Settings and set Alternate Domain Names to your Domain name. Choose Custom SSL Certificate. If your certificate generation was successfully verified in the previous section you'll see your domain once you click into the text filed below.
Choose Custom SSL Certificate and select your domain from the dropdown menu
Set Default Root Object to match the selected file on your S3 bucket. Usually index.html. When ready, press Create Distribution
CloudFront will take a few minutes to spin up your new distribution. Once it's finished, click on the Distribution ID to open the Distribution Settings page.
On General tab, find Domain Name ending in cloudfront.net. Copy it to your clipboard for use in the next section.
We're almost done. Our CloudFront distribution contains a valid SSL certificate and we need only to map the URL to the one of our choosing. We'll do that by removing our old S3 HTTP endpoint alias and replacing it with the HTTPS endpoint generated by CloudFront.
And you're done. You'll now be able to access your site through the HTTPS version of your specified domain.
Further reading:
https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html