Optimize AWS with the Instance Scheduler – Part I

Disclaimer: This is a personal weblog. The opinions expressed here represent my own and not those of my employer.

Only paying for the resources required is a main benefit to utilizing the public cloud. I have seen firsthand the inefficient use of resources which potentially leads to the over and under-utilization of resources. Controlling these resources and their associated costs within AWS is something that I have the opportunity to help customers with regularly. One mechanism for reporting on costs is through the effective use of Tags. A solid tagging strategy is a must! This post will dive into the AWS Instance Scheduler and how this solution leverages Tags to help control resources and their and their associated costs.

Instance Scheduler is found within the AWS Solution Portfolio

AWS Instance Scheduler Solution

The AWS Instance Scheduler is easily deployed into an AWS Account and provides a serverless architecture to automatically start, stop and resize Amazon EC2 and Amazon RDS instances. The Instance Scheduler includes a pre-configured AWS CloudFormation template to get up and running quickly. Following AWS Landing Zone principles, the Master Account (usually the payer in the organization) is typically owned by the Cloud Center of Excellence (CCoE) team. In a multi-account Organization the solution should be deployed within this Master Account providing centralized control and full support for cross-account instance scheduling.

AWS Instance Scheduler Serverless Architecture

Deploying the CloudFormation Template

When walking through the inputs within the template a tag for associating instance schedules is chosen. The default is ‘Schedule’ – Also defined is the services to schedule (Amazon EC2 and/or RDS), the interval at which the Lambda function runs (default 5 minutes – this is quite good for initial testing), time zones and lastly, calling out the start and stop tags. These tags are applied on started and stopped instances. This is very good for cross-account reporting in Cost Explorer for example.

CloudFormation Stack details

Once the stack deployment is started you can follow along and check progress within the CloudFormation Stack [ InstanceScheduler ] Events within the AWS Management Console.

Instance Scheduler DynamoDB Tables

Now that that the Instance Scheduler Solution is deployed in the Master Account of our organization go ahead and take a peek into the created DynamoDB tables. For the most part this is where the bulk of the configuration occurs.

InstanceScheduler-ConfigTable – This table controls the configuration and is where much of the additional customizations will occur.
InstanceScheduler-StateTable – This table records the state of instances across all accounts which Instance Scheduler is utilized. Good information

InstanceScheduler-ConfigTable – config scheduler options

Within the config the default_timezone and tagname are just a few variables which are able to be edited. The started_tags and stopped_tags are also able to be adjusted too. In the next post we’ll go through and make few customizations for our production account which we’ll deploy the Instance Scheduler solution within.

Default uk-office-hours and us-office-hours

By default there are 2 schedules pre-created to use – Within DDB you can copy one of these to edit and rename to fit the needs of your business. You could also edit the office-hours period too. For example, many organizations are global with many differing schedules and hours where instances maybe utilized. Perhaps instances only need to be run for a short period at the end of the month for processing – this is just one example. It is very easy to create periods and associate them with a corresponding schedule

Editing the periods within DynamoDB

Alternatively the Scheduler Command Line Interface may also be used to configure schedules, periods as well as provide a basic cost savings estimate for the given schedule.

Making Magic Happen

If the Schedule Tag is not present on the instances there are a few different ways to update tags of instances.

1.) Utilize Tag Editor and perform in bulk

2.) Scripting! Personally I prefer PowerShell – it’s what I am relatively good at – aspiring to get better every day. Here’s a short snip-it which can be applied to instances.

Below is a screenshot depicting the EC2 section of the AWS Management Console with all of my correctly tagged instances. Calling out below the running / stopped tag. Simply by flipping this tag the state of the instance is immediately changed upon the next Lambda run.

Correctly tagged EC2 instances within the AWS Management Console

Below is a screenshot of CloudTrail illustrating the ‘Start’ event on 3/8/2019.

CloudTrail illustrating Start event which was initiated by Instance Scheduler


In this post I walked through deploying the AWS Instance Scheduler Solution within a Master Account. The AWS Instance Scheduler solution itself is free (you pay for the serverless resources utilized however) and can make an immediate impact to the cost optimization exercises every organization should be going through – constantly. The next post will focus on deploying the AWS Instance Scheduler solution within child accounts as well as updating the CloudFormation template. Stay tuned!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: