3 reasons hosting my website on AWS S3 didn’t work

Hamid Moosavian
5 min readNov 30, 2020

Pros and cons of hosting a static website on S3

Summary

I wanted to host my simple personal website, and I thought of trying AWS. At this stage, my site consists of only a few static pages.

At first, all went well, but soon I came across some challenges. I could solve a couple of them, but a blocker forced me to move away from AWS to a shared web hosting service provider.

Don’t get me wrong. I’m a fan of AWS, and I help people get their AWS certification. I’m sharing my experience only because it may save you some time, and you can be aware of and plan for the blockers.

I help people get their AWS certification. I’m sharing my experience only because it may save you some time, and you can plan for the blockers I explain.

Options for hosting your site on AWS

There are two options for hosting your website on AWS. You can either spin an EC2 instance, which is equivalent to running your own server or using S3 to host your static pages.

EC2 for web hosting

An EC2 instance enables you to host a dynamic website written in any programming language, and of course, you can host a static website. Like a regular web server, an EC2 instance gives you full flexibility.

S3

S3 service is one of the storage services AWS offers. Besides this main role, it allows you to turn a bucket equivalent to a folder into a static website. The only thing you need to do is to configure the bucket properly as a publicly accessible website.

The main benefit of S3 over EC2 is the cost. While EC2 charges you for every hour the server runs, the S3 price is only dependent on the total storage you consume and the number of calls. For a low traffic website, like my personal website, S3 would make complete sense.

My experience with hosting a static site on S3

It took me less than an hour to do the basic setup, including registering the domain using Route53, uploading the files to S3 and configuring the bucket. This part was delightful because it was smooth sailing. I followed the steps explained on this AWS guideline https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html.

Benefits

The benefits of using AWS S3 for hosting a static website include the following:

  1. Cost — You only for the storage and the number of calls, which is really inexpensive compared to any other option.
  2. Cloudfront — Cloudfront is an AWS service that caches your content in AWS data centers closer to your users. It is a Content Delivery Network, or in short, CDN service, that makes your site load faster for users.
  3. Availability and Scalability — You don’t need to worry about your site's traffic volume, as with the redundancy that AWS provides, it is guaranteed that your website is always up and running. You do not need to change anything manually.
  4. Access to computing services — If you want to add some functionality to your site beyond the JavaScript capability on the client-side and requires computing on the server-side, you have Lambda at your disposal. Lambadas allows you to run code without spinning up EC2 instances.

Challenges

  1. HTTP/HTTPS — The first challenge was to serve my site under HTTPS and redirect HTTP automatically to secure. Here Cloudfront saved the day. You can command Cloudfront to redirect HTTP traffic to HTTPS automatically.

2. SEO friendly URL — The next challenge was redirecting mysite.com to mysite.com/index.html and similarly for all other folders. I don’t want users to type in the full URL. Also, I want my blog posts’ URL to look like mysite.com/blog/post and not like mysite.com/blog/post/index.html.

In this case, Cloudfront could only solve half of the problem.

It allows you to set the Default Root Object, and it means solving the problem for mysite.com, but it does not apply to any other subfolder.

I did some research, and I learned to implement a similar behaviour for other subfolders on the site I needed to invoke Lambda.

Steps are explained in this AWS article https://aws.amazon.com/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/.

I was determined to get this work, so I followed the steps and spent a couple of hours, but things got convoluted, and there were some conflicts with Cloudfront behaviour. It could be because the article is outdated or I needed to do more debugging, but at this point, it was not worth it to spend more time. So, I came in piece with having the index.html in my blog post URLs.

3. Email — Now, I needed to set up an email@mysite.com. I originally thought I could use the Amazon SES service to send and receive personal emails. Amazon SES, like most AWS services, is very economical. However, I learned it does not give you a console to access your inbox. SES is usually used in combination with other services for sending emails. So, my options were either to get Amazon WorkMail or Gmail business, which allows me to have an email address at a non-Google domain.

Amazon WorkMail costs about $4.00 per user per month, and Google for business about $6.00 per user per month.

This was the deal-breaker for me, not that I would go broke because of paying a few bucks for my web hosting. The point is that I could get a shared hosting that would solve all the above three issues out of the box for the same price.

Conclusion

AWS is a great cost-effective solution for hosting static websites, but if you like a full service like email and URL forwarding, you need to use services beyond S3, and that means thinking twice about hosting your website on AWS.

I share productivity tips on Twitter. It would be a pleasure to see you there ;)

--

--

Hamid Moosavian

I am fascinated by human behaviour. I share practical tips and techniques on https://twitter.com/HMoosavian