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

Using the Scheduler CLI Demo


Using Instance Scheduler to Optimize Resource Cost
Start course

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


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: 



In this video, I'll be installing the scheduler CLI; a CLI tool that lets you create schedules and periods without directly modifying the DynamoDB table. To use the Scheduler CLI you'll need to install the Scheduler package. You can find instructions on how to do so in the AWS documentation that I will link for you. To use this tool, you'll need to have Python installed. The CLI tool enables you to perform create-like operations for your schedules and periods. 

For example, you can run commands like create-period, create-schedule, delete-period and delete-schedule; update-period and update-schedule. And I can also list out periods and schedules by using the describe-periods and describe-schedules commands. Once you install the tool you can call it by using the keywords 'scheduler-cli'. For example, to verify installation, I can type in 'scheduler-cli --version'. It then returns the version number back which verifies that the install was a success. From here, I can easily build custom periods and schedules.

For example, say I want to create a schedule for a company that provides a benefit called Summer Fridays. Summer Fridays lets employees of that company leave at noon on Friday to take advantage of the summer. In this video, I'll use the instant scheduler to shut down EC2 instances after employees leave at noon every Friday. So, to create the schedule using the Scheduler CLI, I'll first use the create-period command. I'll type in 'scheduler-cli' to call the tool, then create-period. I'll name the period using '--name' and a made up name such as 'summer-fridays'. Then I'll specify the begin time using '--begintime' which will be 09:00 o'clock and '--endtime' which will be 12:00 o'clock. 

Then I'll specify the days of the week this will run for which is just Friday. So, I'll type in '--weekdays fri' and then I'll specify how many months it will run for using '--months may-aug' and then last I'll need to specify the cloud formation stack name I used to install the instance scheduler. This is required for every command to reference the appropriate Instance Scheduler as you can have multiple installations. So, I'll use '--stack' and the stack name 'InstanceScheduler' and then press 'Enter'. Stacks are region specific, so be sure your CLI is using the correct region.

If your default region is different from the region you installed your stack in, you can always use the --region parameter to specify the correct region. All right, so it looks like my period was successfully created. Time to create a schedule that uses this period. So, to do this, I'll use the command, 'scheduler-cli create-schedule'. I'll then use '--name' to provide it to the name "summer-hours". Then I'll specify the period using '--periods' and then use the name of the period I just created which is "summer-fridays". 

The time zone using --timezone and then specifying US/Pacific and then this stack by using '--stack' and the name InstanceScheduler. And I'm also going to add on to this command a parameter called '--enforced'. This prevents an instance from being manually started or stopped outside of the scheduled period. From here I'll click 'Enter'. And now it looks like my schedule has been created. To verify that it was successful, we can look at our creative period in schedule and the DynamoDB config table. So, here I am in the DynamoDB dashboard. I'll click on the 'Config Table' and then I'll click 'Explore Table Items' and if I scroll down, I can see the summer-hours schedule and the summer-fridays period.

Now, let's test it. To do this, I'll go to the EC2 console, click on 'Instances', select My Instance, click on the Tags tab, select Manage Tags, add a new tag with a key of schedule and a tag value of summer-hours and then click 'Save'. Currently it is a Tuesday for me right now. So, I'm outside of the range of the schedule as it only runs a half day on Fridays. Therefore my Instance should soon be in the stopped state. As you can see my Instance is currently in the running state and if I give it a few minutes, the Lambda function will recognize it's not in the appropriate states and shut it down. 

All right, a few minutes later and after a few refreshes, I can see my function is currently in the stopped state, thanks to the enforced schedule. If I didn't enforce the schedule, the instance would have remained in the running state. The Instance Scheduler is an easy way to create schedules and periods without having to directly duplicate items within the table or by creating custom resources in cloud formation. If you use this tool, I'd recommend taking a look at the CLI reference docs. That's it for this one, I'll 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