1. Home
  2. Training Library
  3. Amazon Web Services
  4. Amazon Web Services Courses
  5. Using Instance Scheduler to Optimize Resource Cost

What is the AWS Instance Scheduler?

Contents

keyboard_tab
Using Instance Scheduler to Optimize Resource Cost
1
Introduction
PREVIEW2m 31s
What is the AWS Instance Scheduler?
Difficulty
Intermediate
Duration
29m
Students
21
Ratings
5/5
starstarstarstarstar
Description

In this course, we explain how to use the AWS Instance Scheduler to control EC2 and RDS instance spend. You’ll learn how to automate the stopping and starting of your instances with this tool so that you can reduce costs across your AWS environment.

Learning Objectives

  • What the tool is and the benefit it provides
  • How to implement the tool
  • How to create custom schedules to stop and start your instances

Intended Audience

  • Those who are using EC2 or RDS instances and looking to better control costs for those instances when they are not in use
  • If you’re a developer, cloud engineer, or cloud financial operations professional looking to optimize instance spend

Prerequisites 

To get the most out of this course, you should have an understanding of Amazon EC2, Amazon RDS, Amazon DynamoDB, Amazon CloudFormation, and Amazon CloudWatch.  For more information on these services, please see our existing content: 

 

Transcript

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

Alana Layton is an experienced technical trainer, technical content developer, and cloud engineer living out of Seattle, Washington. Her career has included teaching about AWS all over the world, creating AWS content that is fun, and working in consulting. She currently holds six AWS certifications. Outside of Cloud Academy, you can find her testing her knowledge in bar trivia, reading, or training for a marathon.

Covered Topics