What is the AWS Instance Scheduler?


Course Introduction
Cost Management
6m 51s
Improve Planning and Cost Control with AWS Budgets
AWS Cost Management: Tagging
Understanding & Optimizing Storage Costs with AWS Storage Services
Amazon S3 and Glacier
PREVIEW16m 56s
AWS Backup
Using Instance Scheduler to Optimize Resource Cost

The course is part of this learning path

What is the AWS Instance Scheduler?
2h 33m

This section of the AWS Certified Solutions Architect - Professional learning path introduces you to cost management concepts and services relevant to the SAP-C02 exam. By the end of this section, you will know how to select and apply AWS services to optimize cost in scenarios relevant to the AWS Certified Solutions Architect - Professional exam. 

Want more? Try a Lab Playground or do a Lab Challenge

Learning Objectives

  • Learn how to improve planning and cost control with AWS Budgets
  • Understand how to optimize storage costs
  • Discover AWS services that allow you to monitor for underutilized resources
  • Learn how the AWS Instance Scheduler may be used to optimize resource costs

When you look at any AWS bill, you might find that instance costs are one of the top categories of spend for most companies. If you want to reduce this spend, it’s typically recommended to look at other EC2 pricing options like reservations or spot, right-size your instances, and stop instances that aren’t in use. You can use all of these recommendations, however, in this lecture I’ll mostly be focused on reducing cost by stopping unused instances. 

Now, stopping instances is pretty easy to manage when you only have one or two instances. You simply find the one that isn’t being used and stop it. But what if you have hundreds of instances across multiple Regions and multiple accounts? Well, then it gets complex and you need to rely on automation. 

To automate this process, you can use a tool called the AWS Instance Scheduler. The Instance Scheduler provides a way to stop and start your EC2 or RDS instances automatically using a schedule that you set. It was created so that AWS customers can minimize instance costs across their entire AWS environment, spanning multiple Regions and multiple accounts.  

So how do you use this tool? If you go to the AWS console and search for Instance Scheduler, you won’t find a matching service. Instead, it is offered as a CloudFormation template that you can run in your AWS account. 

When you upload this template to the CloudFormation service, you’ll define several different parameters, including a tag name. This tag name is how you identify which instances should be stopped or started by the Instance Scheduler. The default name is Schedule, however, you can change it to any word or phrase that you can easily remember. 

After setting the parameters, you’ll then run this template and it will deploy several services on your behalf, including: 

  1. A Lambda function

  2. DynamoDB tables

  3. IAM roles and policies,

  4. KMS keys, and 

  5. A CloudWatch event and a log group for the scheduler

After the template creates these resources, the first thing you’ll do is define your Schedules. When creating a schedule, you’ll give it a name, such as monthly-report-schedule. You’ll then use this name to tag your EC2 or RDS instances. The tag key will match the name you provided in your parameters, which defaults to Schedule. And the tag value will be the name of your schedule, in this case, monthly-report-schedule. 

The other major piece of a schedule that you’ll need to define is a period. This is where you choose the times your instance should run. You can define periods as months, days out of the month, days out of the week, or by using hours. For example, your monthly-report-schedule could use a period that runs the instance on the last day of the month, from 9 to 5 pm, every month. 

You can create periods and schedules in several ways. You can modify and create these directly in the DynamoDB table. You can use a tool called the Scheduler CLI, which you can download and run to create Schedules from the command line or you can create a CloudFormation custom resource. Keep in mind if you choose CloudFormation custom resources to create your schedules, you cannot use the DynamoDB console or the Scheduler CLI to modify that schedule in any way as it will cause conflicts and lead to a lot of frustration on your part down the line. 

Once you define your schedules, the Instance Scheduler will start working. It starts with a CloudWatch event that runs on a schedule using a cron expression, triggering your Lambda function at a frequency that you specify. The default is 5 minutes - so every 5 minutes, it will invoke your function and Lambda will then check the current instance state and compare that to the schedule you defined in DynamoDB. If the state defined in the schedule differs from the current state, the Lambda function will update CloudWatch metrics, and then stop or start your instance to match the targeted state. 

In the CloudWatch metric data, you will see information like the name of the instance, the number of instances associated with that schedule, and the number of running instances. 

The price of the instance scheduler is quoted to be $9.90 for the North Virginia Region, or us-east-1. This cost does rely on a large number of factors such as how often you run your Lambda function and how long the function runs, and how many reads/writes to your DynamoDB tables, plus storage costs for the DynamoDB table. The quoted prices assume a very high number for all of these factors. So depending on your actual numbers, it will probably be much cheaper than quoted. Optionally, if you choose to enable CloudWatch metrics, there are additional costs associated with that of around $.90 per schedule you run. 

In summary, the instance scheduler helps you automate the stopping and starting of EC2 and RDS instances to help you optimize your cost. All right, that’s all for this one - see you next time!

About the Author
Learning Paths

Danny has over 20 years of IT experience as a software developer, cloud engineer, and technical trainer. After attending a conference on cloud computing in 2009, he knew he wanted to build his career around what was still a very new, emerging technology at the time — and share this transformational knowledge with others. He has spoken to IT professional audiences at local, regional, and national user groups and conferences. He has delivered in-person classroom and virtual training, interactive webinars, and authored video training courses covering many different technologies, including Amazon Web Services. He currently has six active AWS certifications, including certifications at the Professional and Specialty level.