How I Made This Site - Hosting At 53 Cents A Month - Part 1
Intro: Watch out! This is a long post and most likely will be updated over time as I go through the motions of setting up a site as I describe below with a friend. If any of the below information is inaccurate or unclear please email me at the information provided under about / contact.
As an application developer, I am very comfortable with local development. Once I have an app or a technology installed and set up -- the set up on my computer or the configuration harness for the technology is usually the hardest part for me -- I am good to go. Once I have what I need running on my machine, I am ready and excited to start developing. However, when it comes to managing software in “the cloud”, I can get a little nervous because managing infrastructure is not my strongest suit.
The fact is sad but true -- unlike applications, their processes, libraries, design patterns and language specifications, I do not understand sufficiently enough in my opinion the systems and infrastructure upon which these applications rely. These systems -- such as, IP/TCP, firewalls, security groups, servers, DNS, TLS, Operating Systems, Virtual Machines and Containerized Environments, just to name a short list of very important systems that many applications rely upon -- make applications available to users for consumption. Without these systems, the applications that we developers create will just stay on our machines, and there will be neither users nor customers to enjoy our creations.
Sure -- I could use the wide gamut of options like squarespace, contently, wordpress.com etc… to host a site and just focus on what I think I’m good at: HTML, CSS, JavaScript. If I had a robust application, I could even use something like heroku where I would be able to have my cake and eat it to: a backend that’s fully customizable with little to no maintenance of its infrastructure. Lately I’ve also been looking into serverless services like Zeit. In any event, I fully embrace the point made here, Embracing NoOps.
By conflating the role of an application developer with the role of an operations engineer, organizations are spending more time managing their infrastructure than the real challenge: delivering features their users will value.
I personally could not agree more, and that is why for robust applications whose infrastructure I am responsible for maintaining I go with Heroku. The dollar amount spent on heroku is significantly more valuable from the perspective of a dev team's effectiveness than the days, weeks -- if not months -- of time and effort it would take to design, maintain and scale infrastructure for which the team is responsible.
However, having said that, learning about systems and infrastructure has given me a less myopic view of technology and of what I do as an application developer. Getting “my hands dirty” with infrastructure has appropriately in my opinion broadened my knowledge as a developer to my benefit. I also now better understand what the hardworking system administrators have to deal with on a day to day basis. With growing understanding of systems and infrastructure, I feel more cross functional as a team member and can better emphasize folks in DevOps and system administration.
As is always the challenge when it comes to learning something, I must say to myself, “How must I learn this?”. While video tutorials, blog posts and books are great, more often than not there is nothing like an appropriately measured side project that targets the skill set and knowledge that I want to learn. To learn more about infrastructure and systems, I decided to set up robskrob.com on an s3 bucket in AWS.
Why not set up the project on either ec2, elastic beanstalk or leverage docker to containerize the app process powering my site?
Originally I planned on using elastic beanstalk as my choice for infrastructure, supporting my site. I even got the site up and running on elastic beanstalk, using Rails and Wordpress. Eventually, I got hit up by AWS billing and learned that just having two elastic beanstalk apps -- one for production and one for staging -- would cost me roughly $20 to $30 a month. For my personal site, that was way too much money for me. For affordability reasons I decided to host my site with s3.
Now, let’s get to what I used and how I did it to make my current site.
Here’s a list:
Remotely:
- s3, for hosting
- s3 redirects non
wwwtraffic,robskrob.comtowww.robskrob.comso my site has one uniform address. - cloud front to allow for TLS and to act as a CDN
- ACM to provide my domain name with a certificate
- route53 for DNS
Locally on my MacBook pro:
- a deploy script leveraging AWS’s
awscli to upload html, CSS and JS files to thes3bucket - of course an app process (I use Rails and Wordpress -- more on that later) that relies on
mysqlandredis - three dot files that let me leverage environment variable data per QA, Production and local environment
Let’s tackle the first group of remote technologies that allow me to make this site, robskrob.com, publicly available on what we commonly refer to as, the internet.
s3
s3 hosts my site. Meaning, s3 stores my HTML, JS and CSS files. Here’s a step by step guide to how I set up a bucket that works for my site:
- Visit the
s3dashboard. - Click on
Create bucket - Give the bucket a name. I named it
www.robskrob.com. In our tutorial let’s call it,www.extremedogwalking.club. If the name is already taken AWS will flash validation errors letting you know. I suppose the name must be unique for AWS. - Do not
Block public access. We want to make all the contents of our bucket publicly available. - Eventually you will get to “create the bucket” -- when you get there, just create the bucket.
- Visit the permissions of your recently created bucket and click on the
Bucket Policytab. Enter the following permissions -- as of 07/21/2019 these permissions provided public access to a s3 bucket:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::www.extremedogwalking.club/*" } ] }Click on the properties tab -- should be next to the overview tab -- and then click on the Static website hosting card.
Select
Use this bucket to host a websiteand enterindex.htmlunderIndex document.Click
save.Click back into the Static website hosting card and see that AWS s3 has provided you with a link
http://www.extremedogwalking.club.s3-website-us-east-1.amazonaws.com.Click on your bucket and upload a file called,
index.html. Add some HTML boiler and just for fun in thebodyplace<h1> My Site </h1>.When you visit the above link,
http://www.extremedogwalking.club.s3-website-us-east-1.amazonaws.com, the browser takes you to the above url and receives theindex.htmlfile. You should see the textMy Sitein the page of the browser.
For a potentially more thorough tutorial, here’s a tutorial on hosting a static site with s3.
ACM
AWS Certificate manager let's you create a verified certificate which enables you to enable https -- SSL/TLS -- for your hosted site so network communication can be secure. TLS is a topic that deserves it's own post but for now, I will just guide you through the steps I took to create a TLS certificate so I could enable a secure network protocol for clients exchanging data with robskrob.com:
- Visit the ACM dashboard
- click
Request a certificate - select
Request a public certificateand then click onRequest a certificate. - enter
*.extremedogwalking.clubas theDomain name. - click
Add another name to this certificateand enterwww.extremedogwalking.clubandextremedogwalking.club - select
DNS validationas your validation method and click onReview. - You should see
*.extremedogwalking.clubas your domain name and as additional names:extremedogwalking.clubandwww.extremedogwalking.club. - Click
Next. - Click on
DNS validationto verify that you are the owner ofwww.extremedogwalking.cluband then click Review - Click
Confirm and request - Click on
Export DNS configuration to a fileto get access to the record values that you will need to confirm that you own this domain. - Click
Continue - Head over to
Route53to set up DNS and finish up the verification process so you can own a certificate that will allow you to host your site usinghttps.
Route53
DNS is a topic deserving of its own post -- most likely multiple ones. I’ll just take you through the somewhat rudimentary steps in setting up DNS for your domain name because chances are, http://www.extremedogwalking.club.s3-website-us-east-1.amazonaws.com , is not good enough for you. You want something like https://www.extremedogwalking.club.
- Click on
Create Hosted Zoneat Route53’s dashboard. - Enter
extremedogwalking.club. - Click
Create. - Notice the row
NSand the four values to its right. Because I bought my domain from namecheap.com I had to insert thoseNSrecords into namecheap’s dashboard under the domain’s management area. If you purchased your domain from somewhere that was not AWS Route53 then you will most likely will need to do the same thing I did -- copy the four NS records and paste them into whatever console is provided by the company you purchased your domain. Effectively what this does is, when a computer looks up the domainextremedogwalking.clubthe first hop takes them to namecheap’s DNS which will then direct the computer looking upextremedogwalking.clubtoAWS, provided that name cheap has the correctNSrecords. - Open up the file you downloaded from
ACMcalled,DNS_Configurationand copy the value underRecord Nameon the*.extremedogwalking.clubrow. - Click
Create Record Setin Route53 console page. - in
Name:paste the value that you copied from theDNS_Configrationfile minus.extremedogwalking.club. - for
Type:chooseCNAME - Return to the file you downloaded from
ACMcalled,DNS_Configurationand copy the value underRecord Valueon the*.extremedogwalking.clubrow. - Enter the copied value into
Value:and clickCreate. - Repeat the above steps from
5-10but use theRecord NameandRecord Valuedata from thewww.extremedogwalking.clubrow -- noting that you will need thewww.part of the record name. - It will take some time but eventually if you return to the ACM dashboard under your certificate for
*.extremedogwalking.clubyou will see anIssuedvalue under theStatuscolumn, which verifies that you are indeed the owner ofextremedogwalking.club. I think it took approximately an hour for me.
Cloudfront
Is a CDN that allows for anyone around the world equal and quick access to the hosted assets in your s3 bucket -- HTML, CSS and JS. Without Cloudfront we would have two problems:
- Computers accessing your site from Virginia will have a faster time doing so than folks in the Philippines -- or anywhere else in the world.
- Your site will never allow for
https, which allows for encrypted data to pass from the computer with the browser requesting access to your site using HTTP to the s3 bucket hosting your assets. This is a big problem because withouthttpsthe data passing between the client’s browser and your bucket will be in human readable format and subject to one of the many forms of hacking a person’s private information, like, a credit card number, provided that you site allows for users to enter sensitive information like that into a form for example.
Given the above two problems, we definitely want to enable https for communication between our s3 bucket and another’s computer acting as a client with a browser. To do this, we need to take the following steps:
- Visit cloudfront’s dashboard.
- Click
Create Distribution. - Select
Get StartedunderWeb. - Under
Origin Domain Nameenter the url that yours3bucket provided back in step 11 under thes3section:http://www.extremedogwalking.club.s3-website-us-east-1.amazonaws.com - Under
Viewer Protocol PolicyselectRedirect HTTP to HTTPS. - Under
Alternate Domain Namesenterwww.extremedogwalking.club. - Under
SSL CertificateselectCustom SSL Certificate. Within the form field you should be able to select the ACM certificate*.extremedogwalking.club (111111111111) - Click
Create Distribution - Return to the dashboard and notice the
Pendingstate. For this state to change fromPendingtoEnabledcloud front may take a few hours. TheStatuscolumn will also sayIn Progress, and we will have to wait until it changes toDeployed. For better or for worse, a lot of System Administration work involves sitting around and waiting for things to happen so be sure to work on tasks asynchronously in order to not be blocked constantly and indefinitely.
Cloudront and Route53 to associate the CDN with its DNS
- Now let’s return to
Route53’s dashboard and lick on your hosted zoneextremedogwalking.club. - Click on
Create Record Set - Enter
wwwforName: Type:needs to be set toA - IPv4 address- Set
Alias:to,yes. - Set
Alias Target:to the CloudfrontDomain Namevalue — visit the dashboard of cloud front and you should see a rowDomain Namewith a corresponding value in the row. For this to work of course your cloud front distribution has to have successfully beenEnabledunder the itsStatecolumn andDeployedunder theStatuscolumn. Moreover, cloud front also must reference your Issued ACM credentials. - Click
Save Record Set.
Visit www.extremedogwalking.club -- you should now be seeing the same page My Site except the url will be https://www.bucket.com and not the insecure and kinda ugly http://www.extremedogwalking.club.s3-website-us-east-1.amazonaws.com.
At this point we may be happy enough but other’s may notice a critical problem: https://extremedogwalking.club does not exist. Moreover, even if it did exist, how can I rewrite https://extremedogwalking.club to https://www.extremedogwalking.club? Thankfully, s3 has another awesome feature, redirects.
s3 Redirects
- repeat steps
1-8in the aboves3section but instead of naming your bucketwww.extremedogwalking.clubname the bucketextremedogwalking.club. - Click on the
Propertiestab of your bucket and then click on theStatic website hostingcard. - Select
Redirect requestsand in theTarget bucket or domainsection enterwww.extremedogwalking.cluband make sureprotocolis set tohttps. - Click
save
Cloudfront for redirect
- visit the Cloudfront dashboard to create another distribution.
- Repeat steps all the steps from the cloud front section above (steps
1-9) However instead of enteringwww.extremedogwalking.clubunderAlternate Domain Namesenterextremedogwalking.club. Also underOrigin Domain Nameenter the redirect url from your buckethttp://extremedogwalking.club.s3-website-us-east-1.amazonaws.com
Route53 To Give Your Redirect An A-Record
- Visit the hosted zone
extremedogwalking.clubin the route53 dashboard. - Repeat all the steps from
Cloudront and Route53 to associate the CDN with its DNSin creating anA-Record. However, next toName:leave it blank and for theAlias Targetenter the cloud front distribution that points to your bucket, serving as a redirect forextremedogwalking.clubtowww.extremedogwalking.club
Now https://extremedogwalking.club will resolve to https://www.extremedogwalking.club
Also observe how any http urls resolve to their correct and corresponding https urls.
Admittedly this was a very lengthy post and will probably be subject to edits as I should go through all of the above steps again just to make 100 percent sure I did not miss anything. If you made it at the end of this post, congratulations! That was a lot to take in. If any of this is unclear please visit the contact me part of this site and shoot me an email. Eventually I will have comments on this post but until then feel free to send me a message via email.
The next part to cover is my local set up where I develop my site and then upload all the web assets to my s3 bucket. Right now, my site is just a h1 tag of My Site, which is fairly useless. In my next post I will show how I bind the above cloud systems nicely to an application development that is not only fast and flexible but also dirt cheap, costing this developer only 53 cents a month to run a custom and fully operational website.