Friday, 17 May 2019

How I saved 1000s of dollars in one afternoon


I implemented a fairly basic schedule engine in AWS that works on specific tags to control when the machines are up or down.  The cost of our demo kit was starting to add up, so I looked into the console (which is great) and saw that the main costs were EC2 and RDS.  To fix this I followed a two prong approach:


  1. mandatory tagging
  2. schedule for shutdown


Kinda chicken or egg, because the solution I chose defined the tagging.


I basically followed the guides below:


https://docs.aws.amazon.com/solutions/latest/instance-scheduler/welcome.html

https://s3.amazonaws.com/solutions-reference/aws-instance-scheduler/latest/instance-scheduler.pdf


At Fusion5, we defined a single active Tag for schedules and a single schedule stack:


If you use the tag name ScheduleUptime on an EC2 or RDS instance, then this instance will be on a schedule – it's that simple.The fusion5 stack ID is f5sched

If you set your instance to have tag ScheduleUptime

 

The schedules rely on 2 building blocks, periods and schedules.

A period defines the hour day of starting and stopping, kinda like cron.  The schedule uses the period, but has more controls around the behaviour of the EC2 instance when there is an issue (and importantly uses TZ).

 

For Fusion5, we started with the following schedules.


  • NZ-office-hours
  • AU-office-hours
  • AU-7till7
  • NZ-7till7

 

I think that you can work out what they actually mean!

 

1.3      Periods:

 

command to create a period:

 

root@localhost ~]# scheduler-cli create-period --begintime 07:00 --description "7 till 7 baby" --endtime 19:00 --weekdays 0-4 --name 7till7Mon2Fri -s f5sched

{

   "Period": {

      "Description": "7 till 7 baby",

      "Weekdays": [

         "0-4"

      ],

      "Begintime": "07:00",

      "Endtime": "19:00",

      "Type": "period",

      "Name": "7till7Mon2Fri"

   }

}

 

 

1.4      Schedules:

 

 

command to create a schedule:


[root@localhost ~]# scheduler-cli create-schedule -s f5sched --description "Shannon TEsting 9 to 5" --timezone "Australia/Melbourne" --name AU-office-hours --periods "office-hours"

{

   "Schedule": {

      "RetainRunning": false,

      "Enforced": false,

      "Description": "Shannon TEsting 9 to 5",

      "StopNewInstances": true,

      "Periods": [

         "office-hours"

      ],

      "Timezone": "Australia/Melbourne",

      "Type": "schedule",

      "Name": "AU-office-hours"

   }

}

 

1.5      Viewing schedules and periods

1.5.1      Command line

Install the command line

wget https://s3.amazonaws.com/solutions-reference/aws-instance-scheduler/latest/scheduler-cli.zip

 

python setup.py install

 

then you can use this, but of course you need aws command line first (https://shannonscncjdeblog.blogspot.com/2017/06/move-tb-from-nz-to-aus-via-s3-bucket-of.html)

 

 

DynamoDB


There are two tables in DynamoDB

 

The top one is the only one to worry about (they are not really tables either)

 

Basically everything is saved as JSON document:

{

  "begintime": {

    "S": "07:00"

  },

  "description": {

    "S": "7 till 7 baby"

  },

  "endtime": {

    "S": "19:00"

  },

  "name": {

    "S": "7till7Mon2Fri"

  },

  "type": {

    "S": "period"

  },

  "weekdays": {

    "SS": [

      "0-4"

    ]

  }

}

 

 


 

 

No comments:

Extending JDE to generative AI