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

Creating Periods and Schedules 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: 



After you upload the Instance Scheduler CloudFormation template, you can then view all the resources the stack created. For example, here, I am in the DynamoDB dashboard and I can see the stack created three different tables: the config table, the maintenance window table, and the state table. 

The most important of these three is the config table. This table is where schedules and periods are defined. If I click on “explore table items”, you can see there are examples of schedules and periods already propagated in the table. I can also see the attributes for each of these items. For example, periods have a “begin time” and “end time” attribute. Schedules have an attribute to define the period, and an attribute for the time zone and more. 

Let’s look at one of these Schedules in more depth. I’ll click on the Seattle-office-hours schedule. I can see the type is schedule, the name is seattle-office-hours, it has a description, the time zone is us/pacific since Seattle is on pacific time. And then it defines the period. If I click the + box next to period, I can see which period it uses. In this case, it uses the office-hours period. 

Now, I’ll click cancel and find the office-hours period to see how this schedule runs. I’ll find it in the list, and click on it. And now I can see it has a type of period, the name office-hours, and a description. It also has a begin_time of 9:00 and an end_time of 17:00, which is military time that converts to 5 pm. It also specifies the days of the week that the instance runs by using the weekdays keyword. If I click the plus next to weekdays, I can see that these instances run 9 to 5, Monday through Friday. This means these instances are in the stopped state on weekends and after 5 pm on weekdays.

I can use these examples to create my own custom periods and schedules. For example, let’s duplicate the office-hours period and customize it to stop one of my instances currently running in the next 10 minutes. To do this, I’ll click cancel. Actions. And then duplicate item. I’ll name this one stop-in-ten-minutes and then give it a quick description “shuts down an instance at 10:55 am every Tuesday”. 

I’ll then specify my begintime and endtime. This is the time period you’d like your instance to run. It’s written in the format of HH:MM using military time. In my case, I’ll say my begin_time is 10:45. Then I’ll specify my end_time, which is ten minutes from then, at 10:55 am. Then I can specify the days I want this to run. I can choose from weekdays, months, or monthdays. Each of these are a bit unique in how you operate them. 

For example, say I use the period months. You can define months using the first three letters of the month, such as Jan, Feb, Mar or you can use numbers starting at 1. January would be 1, February would be 2, and so on. To select a range of months, you can use a hyphen, such as 1-5 or Jan-May. You can also specify lists using commas, such as 1, 2, 3 to specify the number of months. You can also be more granular if needed, as you can run your schedule every nth month, using a slash. For example, I could use Jan/2, or ½, to schedule my instance to run every second month starting in January. 

You can also specify monthdays, or like normal people would refer to it, days of the month for the schedule to run. Just like months, you can specify a list of days using a comma, a range of days using a hyphen, or select the nth day of the month using a slash. With monthdays, you can also enter L to run an instance on the last day of the month, so you don’t have to programmatically account for which month ends in 30 days and which one ends in 31 days. You can also use W to run on the nearest weekday, for example, if you specify 10W, that means you want it to run on the closest weekday to the 10th of the month. 

Then, there are weekdays.  Unlike the months period that uses an index that starts at 1, weekdays inexplicably starts at 0 instead. So, Monday is 0, Tuesday is 1, Wednesday is 2, and so on. Additionally, you can use a hyphen to specify a range and a comma to specify a list. If you want to schedule an instance to run every nth weekday out of the month, you do this by using the pound key, or a hashtag as the cool people call it. So, you can run an instance the second Tuesday out of the month by specifying Tue#2, or 1#2. And you can use L to run the instance on the last occurring weekday that you specify out of that month. 

In my case, since I want to shut my instance down in the next ten minutes, I’ll say that I want my instance to run every Tuesday since today is currently Tuesday for me and I’ll specify this by using the number 1. Then I’ll click create. 

After I create a period, I can then create a schedule. To create a schedule, I’ll duplicate an existing one. I”ll click on seattle-office-hours, actions, duplicate item. Then I’ll change the name to every-tuesday-ten-minutes. Then I’ll specify the periods I’ll be using, in this case, stop-in-ten-minutes. Keep in mind you can also specify multiple periods if you wanted to. Then, I’ll specify the time zone, and in this case, I’ll just leave it as US/Pacific. From there, I’ll click save. 

Now that I have a schedule created, I can use the name of the schedule to tag my instance. I’ll copy the name of my schedule. Head over to the EC2 dashboard. Click on my instance. Then, I’ll click the tags tab for that instance. Then click manage tags. Select Add a new tag. I’ll use a key name of “Schedule” with a capital S. Remember that you chose this key name when you uploaded your CloudFormation template, and then the value will be the schedule name I just created which is every-tuesday-ten-minutes. From there, I’ll go ahead and click save. 

Then, the Lambda function will stop and start my instances on this schedule. So if I wait just a few more minutes, until 10:55, I’ll see that Lambda automated the stop.  All right, I’ll come back when my instance is stopped

Welcome back, it is officially that time, just a couple minutes after 10:55. I’m currently in my EC2 instance dashboard, and you can see that my instance is currently in the stopped state, so it looks like the instance scheduler did its job. It will remain stopped until the next Tuesday where it will run for 10 minutes and stop again for the week. That’s it for this one - see you soon! 

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