We re-launch CodeSolid on AWS with a post about how we re-launched CodeSolid on AWS. A few years back, when I thought about Amazon I got it pretty much backwards – thinking it was a tool enterprises were adopting but individual developers didn’t have a use for. I later learned that individual developers were here first, and it’s only been since around 2017 or thereabouts when large enterprises started to move to the cloud in a big way.
One of the surprising things I learned about AWS is that it’s fairly simple and cost effective to host a static site using Amazon S3 buckets as the file location and Amazon’s Route 53 as the DNS service.
The steps to doing this are actually fairly simple, assuming you have an AWS account. The first thing you want to do is make sure your domain is available as an S3 bucket name. This is important, because just as domain names in DNS are in a global namespace, so are S3 bucket names, and for now at least, your bucket name and your website name need to be the same. So assuming your web site is “example.com”, you want create an S3 bucket named “example.com”. So for a new domain name.
For a new domain name, once you’ve verified that the name hasn’t been registered, you can create your bucket name then register the domain using Route 53. For an existing domain, I recommend creating the bucket before you transfer the domain to Route 53.
Once you have the bucket set up on AWS and the web site hosted on Route 53, what’s left to do is:
- In your S3 bucket, under Permissions / Static Web Site Hosting, select “Use this bucket to host a web site”. Enter values for the index document and the error document. (I left the defaults, index.html and error.html, respectively).
- In Route 53, ensure you have a hosted zone for your web site. If you’ve registered your domain with Route 53 or transfered it site here, that should already be set up for you.
- In Route 53, with your hosted zone selected, click “Create Record Set”, and in the edit record set window: Leave the name the same as your web site, i.e., “example.com” Check Yes next to Alias Set the type of record as “A - IPv4 address” Under Alias Target, navigate to your S3 bucket and select it “example.com”. Selecting it will enter a longer AWS website address for the bucket. Leave the routing policy set to simple Under evaluate Health, check “Yes”.
You can upload your files using the Console GUI or using a one-line batch or shell script:
aws s3 cp --acl public-read --recursive public s3://example.com