I was caught off guard. 🙈
Apparently, S3 doesn’t allow to access static website endpoints if the S3 bucket has been chosen as the origin domain name in the CloudFront distribution configuration. At first, it’s also not straight forward to understand what exactly is going on. The first thing when I saw the
AccessDeniederror message when I tried to open one of my blog posts.I thought that this was because of the S3 bucket permissions, so after attempting to update the bucket policy, it became evident that this is not the case. After digging around the internet, I found few older posts that vaguely referred to change the origin to the S3 bucket endpoint. However, it’s not possible once the CloudFront distribution is already created, so here are the steps that I followed!
<Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> <RequestId>???</RequestId> <HostId> ??? </HostId> </Error>
- Delete your current CloudFront distribution. It takes around 15 minutes to disable, after which you can delete.
- To find out what is your S3 bucket endpoint. Go to your S3 bucket and select
Static website hostingfrom the
Propertiestab and you should be able to see your S3 bucket endpoint which would look something like this
- While creating the CloudFront distribution, you can enter the S3 bucket endpoint in the
Origin Domain Namefield, and that’s pretty much it.
- If you have your own domain name which you want to use, you can add a CNAME record that points to the
.cloudfront.netin Route 53.
A few days ago I migrated my website from SiteGround shared hosting provider to an instance on DigitalOcean. By doing so, I have stopped paying around £130 to £46 per year. The main reason why I moved to DigitalOcean was that I got $50 in platform credit from GitHub Student Developer Pack. However, after exploring AWS, I found that it’s possible to host static websites on S3 and it would cost me somewhere between $0.50 - $1.50 per month, which is somewhere around £14 per year. I would say that it’s not bad at all, it’s quite impressive savings from £130 to £14. And a few hours later, here we are, my website now lives on S3 with the help of CloudFront and Route 53. As search engines prefer sites with HTTPS, I also decided to use Let’s Encrypt, and thanks to S3/CloudFront plugin for Certbot client it was like a walk in the park. To setup a static website on S3 you can follow Amazon’s tutorial which can be found here. …
As a WordPress user, I found myself thinking about some alternatives, not because I wouldn’t like Wordpress, but because of how much resources it demands, especially for a simple personal website, which easily could be few basic static HTML pages. Therefore, I decided to push myself outside my comfort zone to see what else is out there. And then, I stumbled across Jekyll, a static website generator. After some experimentation, it just felt wrong not to use it. One of the main reasons why I decided to migrate over Jekyll was that I wouldn’t need to host PostgreSQL db and Wordpress, instead of that I could use the precious server resources in more efficient ways, for example running my Pixelator Twitter bot. …