Menu
AWS Instance Scheduler
AWS Instance Scheduler

Solution Components

Scheduler Configuration Table

When deployed, the AWS Instance Scheduler creates an Amazon DynamoDB table that contains global configuration settings. To modify these global configuration settings after the solution is deployed, update the AWS CloudFormation stack. Do not modify these values in the DynamoDB table. If you modify the values in the DynamoDB table, you will create a conflict between the stored parameters in the stack and the values in the table.

Global configuration items contain a type attribute with a value of config in the configuration table. Schedules and periods contain type attributes with values of schedule and period, respectively. You can add, update, or remove schedules and periods from the configuration table using the DynamoDB console or the solution’s command line interface.

Schedules

Schedules specify when Amazon Elastic Compute Cloud (Amazon EC2) and Amazon Relational Database Service (Amazon RDS) instances should run. Each schedule must have a unique name, which is used as the tag value that identifies the schedule you want to apply to the tagged resource.

Periods

Each schedule must contain at least one period that defines the time(s) the instance should run. A schedule can contain more than one period. When more than one period is used in a schedule, the Instance Scheduler will apply the appropriate start action when at least one of the period rules is true. For more information, see Period Rules.

Time Zone

You can also specify a time zone for the schedule. If you do not specify a time zone, the schedule will use the default time zone you specify when you launch the solution. For a list of acceptable time zone values, see the TZ column of the List of TZ Database Time Zones.

Enforced Field

Schedules contain an enforced field that allows you to prevent an instance from being manually started outside of a running period, or manually stopped during a running period. If this field is set to true and a user manually starts an instance outside of a running period, the solution will stop the instance. If this field is set to true, it also restarts an instance if it was manually stopped during a running period.

Retain Running Field

The retain_running field prevents the solution from stopping an instance at the end of a running period if the instance was manually started before the beginning of the period. For example, if an instance with a period that runs from 9 am to 5 pm is manually started before 9 am, the solution will not stop the instance at 5 pm.

Override Status Field

Schedules also contain an override_status field that allows you to temporarily override the solution’s start and stop actions. If you set the field to running, the solution will start but not stop the applicable instance. The instance will run until you stop it manually. If you set the field to stopped, the solution will stop but not start the applicable instance. The instance will not run until you manually start it.

Note that if you set the override_status field to running but use the enforced field to prevent an instance from being manually started outside of a running period, the solution will stop the instance. If you set the override_status field to stopped but use the enforced field to prevent an instance from being manually stopped during a running period, the solution will restart the instance.

Instance Type

For Amazon EC2 instances only, a schedule allows you to specify an optional instance type for each period in a schedule. When you specify an instance type in the period, the solution will start the Amazon EC2 instance with the applicable instance type.

To specify an instance type, use the syntax <period-name>@<instance-type>. For example, weekends@t2.nano. Note that if you specify an instance type for a period that schedules Amazon EC2 instances and Amazon RDS instances, the instance type will be ignored for Amazon RDS instances.

If the instance type of a running instance is different than the instance type specified for the period, the solution will stop the running instance and restart the instance with the specified instance type, if the specified instance type is compatible with the instance configuration of the running instance. For more information, see Compatibility for Resizing Instances in the Amazon EC2 User Guide for Linux Instances.

Schedule Definitions

The Instance Scheduler configuration table in Amazon DynamoDB contains schedule definitions. A schedule definition can contain the following fields.

Field Description
description An optional description of the schedule
enforced Choose whether to enforce the schedule. When this field is set to true, the scheduler will stop a running instance if it is manually started outside of the running period or it will start an instance if it is stopped manually during the running period.
name The name used to identify the schedule. This name must be unique.
override_status When this field is set to running, the instance will be started but not stopped until you stop it manually. When this field is set to stopped, the instance will be stopped but not started until you start it manually.
periods

The name of the periods that are used in this schedule. Enter the name(s) exactly as it appears in the period name field.

You can also specify an instance type for the period using the syntax <period-name>@<instance-type>. For example, weekdays@t2.large.

retain_running Choose whether to prevent the solution from stopping an instance at the end of a running period if the instance was manually started before the beginning of the period.
stop_new_instances Choose whether to stop an instance the first time it is tagged if it is running outside of the running period. By default, this field is set to true.
timezone The time zone the schedule will use. If no time zone is specified, the default time zone (UTC) is used. For a list of acceptable time zone values, see the TZ column of the List of TZ Database Time Zones.
use_maintenance_window Choose whether to add an Amazon RDS maintenance window as a running period to an Amazon RDS instance schedule. This field is ignored for Amazon EC2 instances. For more information, see Amazon RDS Maintenance Window.
use_metrics

Choose whether to enable CloudWatch metrics at the schedule level. This field overwrites the CloudWatch metrics setting you specified at deployment.

Note

Enabling this feature will incur charges of $0.90/month per schedule or scheduled service.

Period Rules

Period rules contain conditions that allow you to set the specific hours, days, and months an instance will run. A period rule can contain multiple conditions, but all conditions must be true for the AWS Instance Scheduler to apply the appropriate start or stop action.

Start and Stop Times

The begintime and endtime fields define when the Instance Scheduler will start and stop instances. If you specify a start time only, the instance must be stopped manually. Similarly, if you specify a stop time only, the instance must be started manually. If you don’t specify either time, the solution uses the days of the week, days of the month, or months rules to start and stop instances.

If you start an instance before the specified start time, the instance will run until the end of the running period. For example, a user might define a period that starts an instance daily at 9 am and stops that instance at 5 pm.


          Regular schedule

If the user manually starts that instance at 5 am, the solution will stop the instance at 5 pm. Note that if you use the retain running field, the solution will not stop the instance at 5 pm.


          Manual start

If you stop an instance before the specified stop time, the instance will not run until the beginning of the next running period. Continuing from the previous example, if the user stops the instance at 1 pm on Wednesday, the solution will not start the instance until 9 am on Thursday.


          Manual stop

Days of the Week

The weekdays field defines which days during the week an instance will run. You can specify a list of days, a range of days, the nth occurrence of that day in a month, or the last occurrence of that day in a month. The solution supports abbreviated day names (Mon) and numbers (0). For more information, see Step 2.

Days of the Month

The monthdays field defines which days during the month an instance will run. You can specify a list of days, a range of days, every nth day of the month, the last day of the month, or the nearest weekday to a specific date. For more information, see Step 2.

Months

The months field defines which months an instance will run. You can specify a list of months, a range of months, or every nth month. The solution supports abbreviated month names (Jan) and numbers (1). For more information, see Step 2.

Period Definitions

The Instance Scheduler configuration table in Amazon DynamoDB contains period definitions. A period definition can contain the following fields. Note that some fields support Cron non-standard characters.

Field Description

Important

You must specify at least one of the following items: begintime, endtime, weekdays, months, or monthdays.

begintime The time, in HH:MM format, that the instance will start.
description An optional description of the period rule
endtime The time, in HH:MM format, that the instance will stop.
months

Enter a comma-delimited list of months, or a hyphenated range of months, during which the instance will run. For example, enter jan, feb, mar or 1, 2, 3 to run an instance during those months. Or, you can enter jan-mar or 1-3.

You can also schedule an instance to run every nth month or every nth month in a range. For example, enter Jan/3 or 1/3 to run an instance every third month starting in January. Enter Jan-Jul/2 to run every other month from January to July.
monthdays

Enter a comma-delimited list of days of the month, or a hyphenated range of days, during which the instance will run. For example, enter 1, 2, 3 or 1-3 to run an instance during the first three days of the month. You can also enter multiple ranges. For example, enter 1-3, 7-9 to run an instance from the 1st to the 3rd and the 7th through the 9th.

You can also schedule an instance to run every nth day of the month or every nth day of the month in a range. For example, enter 1/7 to run an instance every seventh day starting on the 1st. Enter 1-15/2 to run an instance every other day from the 1st to the 15th.

Enter L to run an instance on the last day of the month. Enter a date and W to run an instance on the nearest weekday to the specified date. For example, enter 15/W to run an instance on the nearest weekday to the 15th.

name The name used to identify the period rule. This name must be unique.
weekdays

Enter a comma-delimited list of days of the week, or a range of days of the week, during which the instance will run. For example, enter 0, 1, 2 or 0-2 to run an instance Monday through Wednesday. You can also enter multiple ranges. For example, enter 0-2, 4-6 to run an instance every day except Thursday.

You can also schedule an instance to run every nth occurrence of a weekday in the month. For example, enter Mon#1 or 0#1 to run an instance the first Monday of the month.

Enter a day and L to run an instance on the last occurrence of that weekday in the month. For example, enter friL or 4L to run an instance on the last Friday of the month.

When a period rule contains multiple conditions, note that all conditions must be true for the AWS Instance Scheduler to apply the appropriate action. For example, a period rule that contains a weekdays field with a value of Mon#1 and a months field with a value of Jan/3 will apply the action on the first Monday of the quarter.

Cross-Account Instance Scheduling

This solution includes a template (instance-scheduler-remote) that creates the AWS Identity and Access Management (IAM) roles necessary to start and stop instances in secondary accounts. You can review and modify permissions in the remote template before you launch the stack.

To apply automated start-stop schedules to resources in secondary accounts, launch the main solution template (instance-scheduler) in the primary account. Then, launch the remote template (instance-scheduler-remote) in each applicable secondary account. When each remote stack is launched, it creates a cross-account role Amazon Resource Name (ARN). Update the main solution stack with each cross-account role ARN by entering the appropriate ARN(s) in the Cross-account roles parameter to allow the AWS Instance Scheduler to perform start and stop actions on instances in the secondary accounts.


        Cross-account scheduling

Figure 3: Cross-account scheduling

Automated Tagging

The Instance Scheduler can automatically add tags to all instances it starts or stops. You can specify a list of tag names or tagname=tagvalue pairs in the Started tags and Stopped tags parameters. The solution also includes macros that allow you to add variable information to the tags:

  • {scheduler}: The name of the scheduler stack

  • {year}: The year (four digits)

  • {month}: The month (two digits)

  • {day}: The day (two digits)

  • {hour}: The hour (two digits, 24-hour format)

  • {minute}: The minute (two digits)

  • {timezone}: The time zone

The following table gives examples of different inputs and the resulting tags.

Example Parameter Input Instance Scheduler Tag
ScheduleMessage=Started by scheduler {scheduler} ScheduleMessage=Started by scheduler MyScheduler
ScheduleMessage=Started on {year}/{month}/{day} ScheduleMessage=Started on 2017/07/06
ScheduleMessage=Started on {year}/{month}/{day} at {hour}:{minute} ScheduleMessage=Started on 2017/07/06 at 09:00
ScheduleMessage=Started on {year}/{month}/{day} at {hour}:{minute} {timezone} ScheduleMessage=Started on 2017/07/06 at 09:00 UTC

When you use the Started tags parameter, the tags are automatically deleted when the scheduler stops the instance. When you use the Stopped tags parameter, the tags are automatically deleted when the instance is started.

Scheduler Command Line Interface

The AWS Instance Scheduler includes a command line interface (CLI) that provides commands for configuring schedules and periods. The CLI allows customers to estimate cost savings for a given schedule. The cost estimates provided by the schedule CLI are for approximation purposes only. For more information about configuring and using the scheduler CLI, see Appendix A.