This has been a challenging year for all parents, but we are fortunate to be in a situation where we can be technologically creative.

Our daughter’s birthday occurred right before the Covid-19 lockdown, but our son was not so lucky, and we wanted to be creative and make the most of his birthday so he didn’t feel left out or alone.

To that end we had some friends recommend a Minecraft party where kids could join a server and play minecraft together. Despite botching the server mode and inadvertently setting it up for PC players only despite some of his friends having XBOX (woops), the server has become an overwhelming success and it was the “best birthday ever!”

However, the downside is we may have created something of an addict and so while I’m all for gaming (and I have my own struggles with playing well past my bedtime), we needed to setup some tech to turn the server on and off at respectable times to enforce bedtime, and not encourage waking up at 6am to play!

I’ll split this into a couple different posts, but wanted to get ahead of my 2020 goals that are rapidly approaching.

Start Server

import boto3
from datetime import datetime
from pytz import timezone
pst = timezone('America/Los_Angeles')
time = datetime.now(pst)
region = 'us-east-1'
instances = ['YOUR_INSTANCE_ID']
ec2 = boto3.client('ec2', region_name=region)


def lambda_handler(event, context):
    ec2.start_instances(InstanceIds=instances)
    print('Minecraft ' + str(instances) +
          ' startup at: ' + time.strftime("%Y-%m-%d %H:%M"))

Stop Server

import boto3
from datetime import datetime
from pytz import timezone
pst = timezone('America/Los_Angeles')
time = datetime.now(pst)
region = 'us-east-1'
instances = ['YOUR_INSTANCE_ID']
ec2 = boto3.client('ec2', region_name=region)


def lambda_handler(event, context):
    ec2.stop_instances(InstanceIds=instances)
    print('Minecraft ' + str(instances) +
          ' startup at: ' + time.strftime("%Y-%m-%d %H:%M"))

CloudWatch Rule (Scheduler)

Using a cron expression, it took me longer than I’d like to admit to realize the timezone operates in GMT so make sure you convert appropriately for your own timezone.

This example starts the Minecraft server every day at 8:00 AM PST.

Services -> CloudWatch -> Events (Rules) ->