A while ago, I needed a small VPS for my students to practise both in class and at home. I was paying for it myself, so I needed it to be as cheap as possible.

I decided to use an AWS Lightsail VPS.

My students do not need the VPS to be up 24/7 : only during classes and when doing their homework. So I wondered if there would be a way to pay for the VM only when it is running…

I came up with a very basic solution :

  • A simple Flask web portal allows my students to :
    • inquire about the state of the VPS
    • start the VPS for a given amount of time (if it is down)
    • dertermine how much running time is remaining and offer to extend it (if it is up)
  • A set of python scripts based on Amazon’s boto3 handles the VPS lifecycle :
    • When the time is up, it :
      • shuts down the VM
      • snapshots the VM
      • deletes the VM
    • When a VM startup is requested, it simply creates a VM from the snapshot

Of course, this all makes sense only because snapshot storage fees are very low and my VPS is very lightweight (less than 8GB to snapshot, which costs me less than 50 cent a month).

The only drawback is that the IP address changes every time we re-create the VPS. I got arround this by :

  • displaying the IP address on the web portal
  • setting-up DynDNS on the VPS

Of course, I used ansible to set-up the VM so I can reproduce it next year 😉

Everything is available on my github

Login Page

Status Page