Few months ago (less than 3), I’ve switched my website from Wordpress to Hugo. There I described the process of setting up Cloudfront distribution to serve as a CDN and a simple web-server for the content backed by S3 bucket.

One of the challenges was how to serve nested paths (eg. /about-me/) as Cloudfront doesn’t know for “directory index” concept. You can only set index for / uri. To tackle that issue, I’ve used Lambda@Edge function called standard-redirects-for-cloudfront I’ve found on the internet.

Thing was working perfectly and I was quite happy. Until I received notification that Node.JS 10.x runtime was going to be deprecated. And you guessed it right, this lambda function is based on that particular Node.js version. Unfortunately, function hasn’t been updated in more than year and a half, and by looking at the repository activity I was uncertain if it would receive any updates in the future.

Rewriting the function

Naturally, as mentioned in the original article, I decided to rewrite this function. For the science, eh?

Perhaps it would be easiest if I just updated that existing Node.js based function to a newer runtime version, but I wanted to experiment with either Python or Golang for some time, so I decided to convert it to Python for starters. New function is available on the Github repository cloudfront-directory-index.

It is nothing special, it is a blatant copy of the Node.js one, just converted to use Python :-) With time, I might add few additional options to it, or even rename it. Who knows, time will show.


This has been a really nice adventure in learning. I managed to get a glimpse of how to write Python, while also getting the chance to better understand whole Lambda@Edge event/trigger flow. Python is such a simple and powerful language and I was quite amazed on how quickly I managed to convert existing code, that I barely understood, to its logic.

Getting it to work on the first try has been really empowering for me, and hopefully a motivation for future endeavours in learning Python.