Using the Scheduler CLI Demo


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

Start course
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

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
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.