As an active web developer I very often start small personal side-projects (which are rarely finished by the way, but that’s another issue :)… Some projects go totally inactive after some time but some of them are still online and attract a few visitors.

And like many developers I sometime use Platforms as a Service like Heroku to host most of my personal projects. Of course, everyone has their own preferences on how to host their projects. Some friends even prefer to host them on their own dedicated servers and practice their sysadmin Unix skills at the same time… That’s great… but I prefer not to maintain servers — even my own ones — and just `git push` my work and delegate the rest.

A few weeks ago I became very interested in Serverless. My goal was to deploy a small Proof of Concept to get a feel of this new technology. For those who wonders what Serverless is… it’s mainly a tool around a new way of deploying and architecting web applications called Function as a Service.

It’s one level even higher than Platform as a Service. With a Platform as a Service provider you still have to use a Web framework to define your routes, have your own web server in the front and need your instance or dyno to be ‘on’ to serve requests.

By using a Function as a Service provider, you only push a function (a simple block of code) to the provider, nothing more! And you pay only for the time your function is run. In the case of Amazon and its service Lambda — the most well-known currently — your function is triggered by an event. And an event may be a lot of things (like a new file uploaded on a S3 bucket) and as you may imagine a request to an API endpoint (on AWS the service to define endpoints is called API Gateway). Eventually, Serverless is a tool providing a nice command line interface to automatize the configuration of your provider.

After wondering what kind of idea would be great to experiment… I’ve simply decided to convert one of my very small Ruby on Rails project running on Heroku to Serverless!

Of course this project was mainly static. No back-office, just a small blog with some articles and a few public forms to store some data in a MongoDB collection. The first step was to convert the whole site to a static website. To do this I chose metalsmith.io. It’s a great Node static generator using a chain of plugins to build. There’s literally a ton of static generators available, you just have to try some of them and stick with your preferred one. The deployment of the site was done on a S3 bucket. Instead of using the DNS server from Amazon (Route 53) I chose to use Cloudflare which provides free SSL protection with just a single click. That’s great for small projects! Eventually to redirect Cloudflare to the bucket, I simply created an Amazon Cloudfront distribution.

All good! Now the best part was to experiment Serverless to handle the few public forms. I wrote the few Node functions to handle the data sent by the browser and used Mongoose (advertised as an “elegant mongodb object modeling for node.js”) to store the data in the same Mongo server used by the former Rails application.

Conclusion

I went from a classical Rails application hosted on Heroku with a “hobby dyno” to a static website using a few Serverless functions. That was such a great achievement that I decided to migrate another small project a few days later. The cost of hosting is now a few cents a month whereas it was about $15 a month on Heroku. It’s really a nice feeling to learn a new technology by yourself and at the same time save a bit of money… I’m just encouraging you to do the same now if you can!

I will soon write detailed articles on how I converted the site. Stay tuned!