I’m not afraid to say that when it comes to spending money, I’m as tight as a duck’s backside. That is why this website, and all my websites are hosted on AWS using S3 buckets configured as static websites.

To make sure they have an SSL certificate, I put Cloudfront in front of the bucket, using a free SSL cert from the AWS certificate manager.

This works well.

That is until you start using a static website tool to generate the websites for you. They are not S3 bucket friendly, in terms that you have to provide a link to a known file, you can just do /blob/article/ and expect it to find an index.html file, or /blog/article and hope it looks for a file called article.html.

This meant for years, I would have to edit the generator files (I’m a big fan of Jekyll) to always make sure that it created a website that was S3 compliant.

Not anymore!!

Cloudfront now has functions. You can write a function and assign it to one or more distributions. This is saving me hours of time rewriting code, I now just assign my function to the distribution and I’m good to go.

function handler(event) {
var request = event.request;
var uri = request.uri;

    if (uri.endsWith('/') === true) {
        request.uri += 'index.html';
    } else if (uri.includes('.') !== true) {
        request.uri += '.html';
    }

    return request;
}