Sample schedules - Instance Scheduler on AWS

Sample schedules

The Instance Scheduler on AWS allows you to automatically start and stop Amazon Elastic Compute Cloud (Amazon EC2) and Amazon Relational Database Service (Amazon RDS) instances. The following section provides some example schedules that can be adapted to many common use cases.

Standard 9-5 working hours

This schedule shows how to run instances on weekdays from 9 AM to 5 PM in London.

Periods

This period will start instances at 9 AM and stop instances at 5 PM on weekdays (Mon-Fri).

Field Value
begintime 09:00
endtime 16:59
name weekdays-9-5
weekdays mon-fri

Schedule

The schedule combines the three periods into the schedule for tagged instances. The schedule includes the following fields and values.

Field Value
name london-working-hours
periods weekdays-9-5
timezone Europe/London

Instance tag

To apply this schedule to instances, you must add the Schedule=london-working-hours tag to the instances.

If you change the default tag name in the AWS CloudFormation Instance Scheduler tag name parameter, your tag key and value will be different. For example, if you entered Sked as your tag name, your tag key will be Sked and the tag value will be Sked=london-working-hours. For more information, refer to Tag your resources in the Amazon Elastic Compute Cloud User Guide.

Scheduler CLI

To configure the above schedule using the Instance Scheduler CLI, use the following commands:

scheduler-cli create-period --stack <stackname> --name weekdays-9-5 --weekdays mon-fri --begintime 9:00 --endtime 16:59 scheduler-cli create-schedule --stack <stackname> --name london-working-hours --periods weekdays-9-5 --timezone Europe/London

Custom resource

The following CloudFormation template will create the above schedule using the schedule custom resource.

To deploy this template, you will need to provide the ServiceInstanceScheduleServiceToken ARN that can be found in the AWS CloudFormation console by selecting the previously deployed Instance Scheduler Hub Stack and then select Outputs.

AWSTemplateFormatVersion: 2010-09-09 Parameters: ServiceInstanceScheduleServiceTokenARN: Type: String Description: (Required) service token arn taken from InstanceScheduler outputs Metadata: 'AWS::CloudFormation::Designer': {} Resources: LondonWorkingWeek: Type: 'Custom::ServiceInstanceSchedule' Properties: NoStackPrefix: 'True' Name: london-working-hours Description: run instances from 9am to 5pm in London on weekdays ServiceToken: !Ref ServiceInstanceScheduleServiceTokenARN Timezone: Europe/London Periods: - Description: 9am to 5pm on weekdays BeginTime: '09:00' EndTime: '16:59' WeekDays: mon-fri

Stop instances after 5 PM

Instances can be started freely at any time during the day and this schedule will ensure that a stop command is automatically sent to them at 5 PM ET every day.

Periods

This period will stop instances at 5 PM every day.

Field Value
endtime 16:59
name stop-at-5

Schedule

The schedule name provides the tag value that must be applied to insances and the timezone that will be used.

Field Value
name stop-at-5-new-york
periods stop-at-5
timezone America/New_York

Instance tag

To apply this schedule to instances, you must add the Schedule=stop-at-5-new-york tag to the instances. If you changed the default tag name in the AWS CloudFormation Instance Scheduler tag name parameter, your tag will be different. For example, if you entered Sked as your tag name, your tag will be Sked=stop-at-5-new-york . For more information, refer to Tag your resources in the Amazon Elastic Compute Cloud User Guide.

Scheduler CLI

To configure the above schedule using the Instance Scheduler CLI, use the following commands:

scheduler-cli create-period --stack <stackname> --name stop-at-5 --endtime 16:59 scheduler-cli create-schedule --stack <stackname> --name stop-at-5-new-york --periods stop-at-5 --timezone America/New_York

Custom resource

The following CloudFormation template will create the above schedule using the schedule custom resource.

To deploy this template, you will need to provide the ServiceInstanceScheduleServiceToken ARN that can be found in the AWS CloudFormation console by selecting previously deployed Instance Scheduler Hub Stack and then Outputs.

AWSTemplateFormatVersion: 2010-09-09 Parameters: ServiceInstanceScheduleServiceTokenARN: Type: String Description: (Required) service token arn taken from InstanceScheduler outputs Metadata: 'AWS::CloudFormation::Designer': {} Resources: StopAfter5: Type: 'Custom::ServiceInstanceSchedule' Properties: NoStackPrefix: 'True' Name: stop-at-5-new-york Description: stop instances at 5pm ET every day ServiceToken: !Ref ServiceInstanceScheduleServiceTokenARN Timezone: America/New_York Periods: - Description: stop at 5pm EndTime: '16:59'

Stop instances over the weekend

This schedule shows how to run instances from Monday 9 AM ET to Friday 5 PM ET. Since Monday and Friday are not full days, this schedule includes three periods to accommodate: Monday, Tuesday-Thursday, and Friday.

Periods

The first period starts tagged instances at 9 AM Monday and stops at midnight. This period includes the following fields and values.

Field Value
begintime 09:00
endtime 23:59
name mon-start-9am
weekdays mon

The second period runs tagged instances all day Tuesday through Thursday. This period includes the following fields and values.

Field Value
name tue-thu-full-day
weekdays tue-thu

The third period stops tagged instances at 5 PM on Friday. This period includes the following fields and values.

Field Value
begintime 00:00
endtime 16:59
name fri-stop-5pm
weekdays fri

Schedule

The schedule combines the three periods into the schedule for tagged instances. The schedule includes the following fields and values.

Field Value
name mon-9am-fri-5pm
periods mon-start-9am,tue-thu-full-day,fri-stop-5pm
timezone America/New_York

Instance tag

To apply this schedule to instances, you must add the Schedule=mon-9am-fri-5pm tag to the instances. Note that if you changed the default tag name in the AWS CloudFormation Instance Scheduler tag name parameter, your tag will be different. For example, if you entered Sked as your tag name, your tag will be Sked=mon-9am-fri-5pm . For more information, refer to Tag your resources in the Amazon Elastic Compute Cloud User Guide.

Scheduler CLI

To configure the above schedule using the Instance Scheduler CLI, use the following commands:

scheduler-cli create-period --stack <stackname> --name mon-start-9am --weekdays mon --begintime 9:00 --endtime 23:59 scheduler-cli create-period --stack <stackname> --name tue-thu-full-day --weekdays tue-thu scheduler-cli create-period --stack <stackname> --name fri-stop-5pm --weekdays fri --begintime 0:00 --endtime 17:00 scheduler-cli create-schedule --stack <stackname> --name mon-9am-fri-5pm --periods mon-start-9am,tue-thu-full-day,fri-stop-5pm --timezone America/New_York

Custom resource

The following CloudFormation template will create the above schedule using the schedule custom resource.

To deploy this template, you will need to provide the ServiceInstanceScheduleServiceToken ARN that can be found in the AWS CloudFormation console by selecting the previously deployed Instance Scheduler Hub Stack and then select Outputs.

AWSTemplateFormatVersion: 2010-09-09 Parameters: ServiceInstanceScheduleServiceTokenARN: Type: String Description: (Required) service token arn taken from InstanceScheduler outputs Metadata: 'AWS::CloudFormation::Designer': {} Resources: StopOnWeekends: Type: 'Custom::ServiceInstanceSchedule' Properties: NoStackPrefix: 'True' Name: mon-9am-fri-5pm Description: start instances at 9am on monday and stop them at 5pm on friday ServiceToken: !Ref ServiceInstanceScheduleServiceTokenARN Timezone: America/New_York Periods: - Description: 9am monday start BeginTime: '09:00' EndTime: '23:59' WeekDays: mon - Description: all day tuesday-thursday WeekDays: tue-thu - Description: 5pm friday stop BeginTime: '00:00' EndTime: '16:59' WeekDays: fri