aws instance scheduler

50
AWS Instance Scheduler Implementation Guide

Upload: others

Post on 17-Oct-2021

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AWS Instance Scheduler

AWS Instance SchedulerImplementation Guide

Page 2: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

AWS Instance Scheduler: Implementation GuideCopyright © Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

Amazon's trademarks and trade dress may not be used in connection with any product or service that is notAmazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages ordiscredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who mayor may not be affiliated with, connected to, or sponsored by Amazon.

Page 3: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Table of ContentsHome ..... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Cost ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Architecture overview .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Instance scheduling workflow ..... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Automated account registration workflow ..... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Solution components .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Scheduler configuration table .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Schedules .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Periods .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Time zone .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Schedule definitions .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Period rules ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Start and stop times .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Days of the week .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Days of the month .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Months .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Period definitions .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Automated tagging .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Scheduler command line interface .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Security ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11AWS Key Management System ..... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Amazon Identity Access Management .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Design considerations .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12AWS Accounts .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Cross-Account instance scheduling using account IDs or AWS Organizations ID .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Partial automation .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Instance shutdown behavior ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Amazon EC2 .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Amazon RDS .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Global configuration settings .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Encrypted Amazon EBS volumes .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Regional deployments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Logging and notifications .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

AWS CloudFormation templates .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Automated deployment .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Deployment overview .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Step 1. Launch the instance scheduler stack .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Step 2. Configure periods .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Step 3. Configure schedules .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Step 4. Tag your instances .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Setting the tag value .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Step 5. Launch the remote stack in the primary account and all secondary accounts in the sameRegion .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Additional resources .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Update the stack .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Instance Scheduler CLI ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Credentials ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Install the Scheduler CLI ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Command structure .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Common arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Available commands .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25create-period .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

iii

Page 4: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27create-schedule .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

delete-period .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

delete-schedule .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

describe-periods .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

describe-schedules .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

describe-schedule-usage .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

update-period .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

update-schedule .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Arguments .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

help .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Description .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Specific Command Example .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Log files .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Custom resource .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Sample schedule .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Periods .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Schedule .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Instance tag .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Scheduler CLI ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Changes in scheduling v2.0.0 .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39Identify the AWS Organizations ID .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40Uninstall the solution .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Using the AWS Management Console .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Using AWS Command Line Interface .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Collection of operational metrics ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Source Code .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Contributors ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Revisions .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

.... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Notices .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

iv

Page 5: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Automate starting and stoppingAWS instances

Publication date: October 2020 (last update (p. 45): October 2021)

The AWS Instance Scheduler solution automates the starting and stopping of Amazon Elastic ComputeCloud (Amazon EC2) and Amazon Relational Database Service (Amazon RDS) instances.

This solution helps reduce operational costs by stopping resources that are not in use and startingresources when their capacity is needed. For example, you can use AWS Instance Scheduler toautomatically stop instances outside of business hours every day. If you leave all of your instancesrunning at full utilization, this solution can save you up to 70% for those instances that are onlynecessary during regular business hours (weekly utilization reduced from 168 hours to 50 hours).

AWS Instance Scheduler leverages AWS resource tags, AWS Lambda, and AWS Systems ManagerAutomation documents to automatically stop and restart instances across multiple AWS Regions andaccounts on a customer-defined schedule.

This implementation guide discusses architectural considerations and configuration steps for deployingthe Amazon Web Services (AWS) Instance Scheduler in the AWS Cloud. It includes links to AWSCloudFormation templates that launch, configure, and run the AWS services required to deploy thissolution using AWS best practices for security and availability.

The guide is intended for IT infrastructure architects, administrators, and DevOps professionals who havepractical experience architecting in the AWS Cloud.

1

Page 6: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

CostYou are responsible for the cost of the AWS services used while running AWS Instance Scheduler. As ofOctober 2021, the cost for running this solution with default settings in the US East (N. Virginia) Regionis approximately $33.24 per month in AWS Lambda charges, or less if you have AWS Lambda free tiermonthly usage credit. The solution also uses AWS Systems Manager (SSM) Automations, which charges$0.002 per step after the free tier period of 100,00 steps per account per month. This is independent ofthe number of Amazon EC2 instances you are running. By default, this solution uses on-demand scalingfor its Amazon DynamoDB tables to provide sufficient read and write capacity.

AWS Instance Scheduler is designed to run AWS Lambda functions to evaluate the schedules, and invokeSSM Automations to start or stop instances based on the periods configured in the schedules. The costof the solution after launch depends on the number of Lambda runs (default is 280 based on every fiveminute invocations per day). Each schedule will require an AWS Systems Manager Automation run foreach account, Region, and service.

The costs in the following table are based on the following assumptions:

1. The solution is deployed in US East (N. Virginia) Region.2. The solution manages EC2 instances, RDS instances, and Aurora clusters.3. The solution manages instances in an additional account.4. The total number of runs per day is 280 runs (Lambda is scheduled to run every five minutes).5. A total of two schedules, each schedule requiring at least one start and one stop action on the

instances.6. The average runtime for the AWS Lambda is eight seconds.7. The memory selected for AWS Lambda is 128 MB.

AWS service Dimensions Cost (per month)

AWS Lambda 280 runs/24 hours

8 seconds per run

($0.0000021/second/run)

<$1.00

AWS Systems ManagerAutomations

5 accounts * 2 Regions * 3services (Amazon EC2/AmazonRDS/Aurora clusters) * 2 numberof schedules * 2 minimumnumber of actions per shedulerper day * 4 steps for eachrunbook

Total runs per day= 5*2*3*2*2*4= 48

Total runs per month= 480 * 30= 14400

Cost per month = 14400 * 0.002= 28.80

$30.24

2

Page 7: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

AWS service Dimensions Cost (per month)

For executeScript: 5accounts, 2 Regions, 2 runbooks,2 number of schedules, 2number of actions per scheduleper day

Total runs per day= 5*2*2*2*2=160

Total runs per month= 160 * 30= 4800

Duration of executeScript =10 seconds

Total duration for month 48000seconds

Cost per month 48000 *$0.00003 = 1.44

AWS DynamoDB 8,640 (write/month)

($1.25 per million requests)

<$1.00

AWS DynamoDB 17,280 (read/month)

($0.5 per million requests)

<$1.00

AWS DynamoDB <1 GB

(First 25 GB is free)

$0.0

Total: ~$33.24

The cost is independent of the number of Amazon EC2 and RDS instances you are running. By default,this solution uses on-demand scaling for its Amazon DynamoDB tables to provide sufficient read andwrite capacity. The AWS services for this solution are listed under Additional resources (p. 22).

Prices are subject to change. For full details, refer to the pricing webpage for each AWS service you willbe using in this solution.

3

Page 8: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideInstance scheduling workflow

Architecture overviewDeploying this solution builds the following environment in the AWS Cloud.

Figure 1: Instance Scheduler on the AWS Cloud

Instance scheduling workflow1. Amazon EventBridge rule in the hub account periodically invokes AWS Lambda in the hub account.2. The Lambda function retrieves and evaluates the schedules from the Amazon DynamoDB table to

identify the start or stop action for each schedule.3. A new AWS Systems Manager Automation starts for each schedule and resource type for all the

customer-defined accounts and Regions.4. AWS Systems Manager Automations run in multiple Regions and accounts from the hub account.

The details for each automation for any spoke account can be analyzed from the hub account.5. The custom AWS Systems Manager Automation documents manage Amazon EC2 state changes.6. The custom AWS Systems Manager Automation documents uses secondary automations to manage

Amazon RDS instance and Aurora cluster states. Custom tags are also applied using AWS SystemsManager Automation documents.

Automated account registration workflow1. An Amazon EventBridge rule in the spoke account uses Amazon EventBridge bus in the hub account

as a target to automate account registration with the Instance Scheduler service in the hub account.This only occurs if you select the option in the spoke template.

4

Page 9: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideAutomated account registration workflow

2. The Amazon EventBridge bus forwards the event from the spoke account to the hub event rule.3. The Amazon EventBridge rule uses the Lambda function as a target to add the spoke account ID into

the configuration in the DynamoDB table.

5

Page 10: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideScheduler configuration table

Solution components

Scheduler configuration tableWhen deployed, AWS Instance Scheduler creates an Amazon DynamoDB table that contains globalconfiguration 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 youmodify the values in the DynamoDB table, you will create a conflict between the stored parameters inthe 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 canadd, update, or remove schedules and periods from the configuration table using the DynamoDB consoleor the solution’s command line interface (p. 24).

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

PeriodsEach schedule must contain at least one period that defines the time(s) the instance should run. Aschedule can contain more than one period. When more than one period is used in a schedule, theInstance Scheduler will apply the appropriate start action when at least one of the period rules is true.For more information, refer to Period Rules (p. 7).

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

Schedule definitionsThe Instance Scheduler configuration table in Amazon DynamoDB contains schedule definitions. Aschedule definition can contain the following fields:

Field Description

description An optional description of the schedule.

name The name used to identify the schedule. Thisname must be unique.

periods The name of the periods that are used in thisschedule. Enter the name(s) exactly as it appearsin the period name field.

6

Page 11: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuidePeriod rules

Field Description

timezone The time zone the schedule will use. If no timezone is specified, the default time zone (UTC) isused. For a list of acceptable time zone values,refer to the TZ column of the List of TZ DatabaseTime Zones.

Period rulesPeriod rules contain conditions that allow you to set the specific hours, days, and months an instanceshould be available. A period rule can contain multiple conditions. If the current time when the Lambdaevaluates the schedule is in between the period rule, then the Lambda will check if the appropriate startaction has been performed for the schedule in the ScheduleStates DynamoDB table. If it doesn’t findthe matching state, the Lambda function will call the AWS Systems Manager Automation runbook tostart the instances.

Start and stop timesThe begintime and endtime fields define when the instances should be running. If you only specify astart time, the instance must be manually stopped. Similarly, if you only specify a stop time, the instancemust be manually started. If you don’t specify either time, instances tagged with the schedule withno periods will always be stopped. Essentially the start and stop times are used to evaluate when thesolution has to start and stop AWS Systems Manager Automations which will now start and stop theinstances.

The begintime and endtime values for your period must be in the time zone specified in the schedule.If you do not specify a time zone in the schedule, the solution will use the time zone specified when youlaunch the solution.

If you want to schedule multiple start and stop actions on your instances, configure the periodsaccordingly. If you manually intervene and start or stop the instances based on changed usage,the scheduler will not change the state of the instance until it evaluates the periods and finds theappropriate action to perform.

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

Figure 2: 9-5 scheduled start and stop

If the user manually starts that instance at 5 am, the solution will stop the instance at 5 pm.

Figure 3: 5 am manual start

7

Page 12: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideDays of the week

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

Figure 4: 5 pm scheduled stop

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

Days of the monthThe monthdays field defines which days during the month an instance will run. You can specify a list ofdays, a range of days, every nth day of the month, the last day of the month, or the nearest weekday to aspecific date. For more information, refer to Step 2 (p. 19).

MonthsThe months field defines which months an instance will run. You can specify a list of months, a range ofmonths, or every nth month. The solution supports abbreviated month names (Jan) and numbers (1). Formore information, refer to Step 2 (p. 19).

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

Field Description

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

description An optional description of the period rule.

endtime The time, in HH:MM format, that the instance willstop.

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

8

Page 13: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuidePeriod definitions

Field Description

You can also schedule an instance to run everynth month or every nth month in a range. Forexample, enter Jan/3 or 1/3 to run an instanceevery third month starting in January. Enter Jan-Jul/2 to run every other month from January toJuly.

monthdays Enter a comma-delimited list of days of themonth, or a hyphenated range of days, duringwhich the instance will run. For example, enter1, 2, 3 or 1-3 to run an instance during the firstthree days of the month. You can also entermultiple ranges. For example, enter 1-3, 7-9 torun 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 monthin a range. For example, enter 1/7 to run aninstance every seventh day starting on the 1st.Enter 1-15/2 to run an instance every other dayfrom the 1st to the 15th.

Enter L to run an instance on the last day of themonth. Enter a date and W to run an instance onthe nearest weekday to the specified date. Forexample, enter 15W to run an instance on thenearest weekday to the 15th.

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

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

You can also schedule an instance to run everynth occurrence of a weekday in the month. Forexample, enter Mon#1 or 0#1 to run an instancethe first Monday of the month.

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

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

9

Page 14: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideAutomated tagging

Automated taggingThe Instance Scheduler can automatically add tags to all instances it starts or stops. You can specify alist of tag names or tagname=tagvalue pairs in the Started tags and Stopped tags parameters. Thesolution 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 schedulerMyScheduler

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/06at 09:00

ScheduleMessage=Started on {year}/{month}/{day} at {hour}:{minute}{timezone}

ScheduleMessage=Started on 2017/07/06at 09:00 {Default timezone selected inthe solution stack}

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

Scheduler command line interfaceThe AWS Instance Scheduler includes a command line interface (CLI) that provides commands forconfiguring schedules and periods. The CLI allows you to estimate cost savings for a given schedule. Thecost estimates provided by the schedule CLI are for approximation purposes only. For more informationabout configuring and using the scheduler CLI, refer to Instance Scheduler CLI (p. 24).

10

Page 15: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideAWS Key Management System

SecurityWhen you build systems on AWS infrastructure, security responsibilities are shared between you andAWS. This shared model reduces your operational burden because AWS operates, manages, and controlsthe components including the host operating system, the virtualization layer, and the physical security ofthe facilities in which the services operate. For more information about AWS security, visit the AWS CloudSecurity.

AWS Key Management SystemThe solution creates an AWS managed Custom Master Key (CMK), which is used to configure server-sideencryption for the SNS topic and the DynamoDB tables.

Amazon Identity Access ManagementThe Lambda function created by the solution requires permissions to start/stop both EC2 and RDSinstances, modify instance attributes, update tags for the instances among other permissions. All thenecessary permissions are provided by the solution to Lambda service role created as part of the solutiontemplate. Additionally, the Lambda service role also has access to get/put SSM parameters, accessto CloudWatch log groups, KMS key encryption/decryption, and publish messages to SNS topic. Fordetailed information about each permission provided to the service role, refer to the CloudFormationtemplates (p. 15).

11

Page 16: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideAWS Accounts

Design considerations

AWS AccountsIn version 2.0.0, you only need to provide a static list of remote accounts, or the AWS Organizations ID.The AWS Organizations ID can be found in the hub account. For more information about the workflow,refer to Changes in scheduling v2.0.0 (p. 39).

The remote account ID will be automatically enrolled while deploying the remote stack in the memberaccount. Refer to the remote stack parameters for more details.

Cross-Account instance scheduling using accountIDs or Organization ID

This solution includes a template (aws-instance-scheduler-remote.template) that creates theAWS Identity and Access Management (IAM) roles necessary to start and stop instances in secondaryaccounts. 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 solutiontemplate (aws-instance-scheduler.template) in the primary account with a distinct namespaceattribute and the list of accounts the solution should schedule instances in. Then, launch the remotetemplate (aws-instance-scheduler-remote.template) in each applicable secondary account withthe same namespace attribute and in the same Region as the primary account was launched in. Wheneach remote stack is launched, it creates a cross-account IAM role that will be used by the solution toschedule start/stop on instances.

Partial automationUsers have the option to implement a partially automated solution by default (for example, configurestart-only or stop-only actions). An example of this is a team that needs the flexibility to stop instancesat varying times (manually) but must start those instances simultaneously each morning, or vice versa.

Instance shutdown behaviorAmazon EC2This solution is designed to automatically stop Amazon Elastic Compute Cloud (Amazon EC2) instancesand assumes that instance shutdown behavior is set to Stop, not Terminate. Note that you cannotrestart an Amazon EC2 instance after it is terminated.

By default, Amazon EC2 instances are configured to stop, not terminate, when shut down, but you canmodify this behavior. Therefore, make sure that the instances you control using the Instance Schedulerare configured with a Stop shutdown behavior, otherwise they will be terminated.

12

Page 17: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideAmazon RDS

Amazon RDSNote that this solution is designed to automatically stop, not delete, Amazon Relational DatabaseService (Amazon RDS) instances.

You can use the Schedule Aurora Clusters template parameter to start and stop RDS instances that arepart of an Aurora cluster or that manage Aurora databases. You must tag the cluster (not the individualinstances) with the tag key you defined during initial configuration and the schedule name as the tagvalue to schedule that cluster.

For more information about limitations to starting and stopping an Amazon RDS instance, refer toStopping an Amazon RDS DB instance temporarily in the Amazon RDS User Guide.

When an Amazon RDS instance is stopped, the cache is cleared which might lead to slower performancewhen the instance is restarted.

Global configuration settingsWhen you deploy the AWS Instance Scheduler’s AWS CloudFormation template, global configurationsettings are stored in an Amazon DynamoDB table (ConfigTable). To modify these settings, update thesolution stack using the AWS CloudFormation template. Do not change these settings in the DynamoDBtable.

Encrypted Amazon EBS volumesIf your Amazon EC2 instances contain encrypted Amazon Elastic Block Store (Amazon EBS) volumes,you must grant the Instance Scheduler permission to use the customer master key (CMK) to start andstop instances. Add the kms:CreateGrant permission to the Instance Scheduler role (<stackname>-SchedulerRole-<id>).

Regional deploymentsYou can deploy AWS Instance Scheduler in any AWS Region. Once deployed, the Instance Schedulerapplies the appropriate start or stop actions to tagged Amazon EC2 and Amazon RDS instances in allRegions in the hub account. If you use cross-account instance scheduling, the solution will apply actionsto instances in all Regions in all provided remote accounts or where the remote template is deployed inyour AWS Organizations.

ImportantInstance Scheduler actions will affect appropriately tagged instances in all AWS Regions of youraccount, even though the solution is deployed in a single Region.

NoteAWS Instance Scheduler has been validated in the following AWS Regions:

• us-east-1 (N.Virginia)• us-east-2 (Ohio)• us-west-1 (N.California)• us-west-2 (Oregon)• eu-west-1 (Ireland)

• sa-east-1 (Sao Paulo)• ap-northeast-1(Tokyo)• ap-northeast-2 (Seoul)• ap-south-1 (Mumbai)• ap-southeast-1 (Singapore)

13

Page 18: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideLogging and notifications

NoteAWS Instance Scheduler has been validated in the following AWS Regions:

• eu-west-2 (London)• eu-west-3 (Paris)• eu-central-1 (Frankfurt)

• ap-southeast-2 (Sydney)• ca-central-1 (Canada)• AWS GovCloud (US-East, US-West)

Logging and notificationsAWS Instance Scheduler leverages Amazon CloudWatch Logs for logging. This solution logs processinginformation for each tagged instance, the results of the period rule evaluation for the instance, thedesired state of the instance during that period, the applied action, and debugging messages.

Warning and error messages are also published to a solution-created Amazon SNS topic which sendsmessages to a subscribed email address (refer to Subscribe to a Topic in the Amazon SNS DeveloperGuide). You can find the name of the Amazon SNS topic in the Outputs tab of the solution stack.

14

Page 19: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

AWS CloudFormation templatesThis solution uses AWS CloudFormation to automate the deployment of AWS Instance Scheduler in theAWS Cloud. It includes the following AWS CloudFormation templates, which you can download beforedeployment:

aws-instance-scheduler.template: Use this template to launch the InstanceScheduler and all associated components. The default configuration deploys an AWS Lambda function,AWS Systems Manager Automation documents, an Amazon DynamoDB table, an Amazon CloudWatchevent, and CloudWatch custom metrics, but you can also customize the template based on your specificneeds.

aws-instance-scheduler-remote.template: Use this template to configurepermissions for instances in secondary accounts. The default configuration creates the AWS Identity andAccess Management (IAM) roles necessary to start and stop instances in a secondary account.

15

Page 20: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideDeployment overview

Automated deploymentBefore you launch the automated deployment, please review the architecture, configuration, and otherconsiderations discussed in this guide. Follow the step-by-step instructions in this section to configureand deploy Instance Scheduler into your account.

Time to deploy: Approximately five minutes

Deployment overviewThe procedure for deploying this architecture on AWS consists of the following steps. For detailedinstructions, follow the links for each step.

Step 1. Launch the instance scheduler stack (p. 16)

• Launch the AWS CloudFormation template into your AWS account• Enter values for the required parameter: Stack Name• Review the other template parameters, and adjust if necessary

Step 2. Configure periods (p. 19)

• Create a period and set the applicable fields for the period

Step 3. Configure schedules (p. 19)

• Create a schedule and set the applicable fields for the schedule

Step 4. Tag your instances (p. 19)

• Apply the custom tag to applicable resources

Step 5. Launch the remote stack in the primary account and all secondary accounts in the sameRegion (p. 20)

• Launch the AWS CloudFormation template into your AWS account and same Region as the primarystack.

• Enter a value for the required parameter: Primary account, Namespace (as provided in the primarystack), select the option if AWS Organizations are being used as selected in the primary stack.

Step 1. Launch the instance scheduler stackImportantThis solution includes an option to send anonymous operational metrics to AWS. We use thisdata to better understand how customers use this solution and related services and products.AWS owns the data gathered though this survey. Data collection is subject to the AWS PrivacyPolicy.To opt out of this feature, download the template, modify the AWS CloudFormation mappingsection, and then use the AWS CloudFormation console to upload your template and deploy thesolution. For more information, refer to the Collection of operational metrics (p. 42).

16

Page 21: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideStep 1. Launch the instance scheduler stack

This automated AWS CloudFormation template deploys the Instance Scheduler in AWS Lambda, andconfigures related components. Ensure that you’ve verified the settings (p. 19) for your instancesbefore launching the stack.

NoteYou are responsible for the cost of the AWS services used while running this solution. For moredetails, visit to the Cost (p. 2) section in this guide, and refer to the pricing webpage for eachAWS service used in this solution.

1. Sign in to the AWS Management Console and click the button to launch the aws-instance-scheduler AWS CloudFormation template.

You can also download the template as a starting point for your own implementation.

2. The template is launched in the US East (N. Virginia) Region by default. To launch the InstanceScheduler in a different AWS Region, use the region selector in the console navigation bar.

3. On the Select Template page, verify that you selected the correct template and choose Next.

4. On the Specify Details page, assign a name to your solution stack.

NoteThe stack name cannot contain more than 36 characters.

5. Under Parameters, review the parameters for the template, and modify them as necessary.

This solution uses the following default values.

Parameter Default Description

Namespace Configuration

Provide a unique namespacevalue

Provide unique identifier todifferentiate between multiplesolution deployments (Nospaces). For example: Dev

Account Structure

Using AWS Organizations No Is the hub account member ofthe AWS Organizations?

Provide Organization Id or Listof Remote Account Ids

(Required) when using AWSOrganizations, provideOrganization ID. For example:o-xxxxyyy. If not, providecomma separated list ofremote account IDs. Forexample: 1111111111,2222222222

Region(s) List of Regions in whichinstances are scheduled, leaveblank if current Region only.

Schedule Configuration

17

Page 22: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideStep 1. Launch the instance scheduler stack

Parameter Default Description

Do you wish to enablescheduling events

Yes Activate or deactivate eventsscheduling.

Default time zone UTC Choose the default time zone.Default is UTC.

Frequency 5 Scheduler running frequency inminutes.

Managed Instances Configuration

Service(s) to schedule EC2 Scheduled services.

Schedule Aurora Clusters No Turn on scheduling of Auroraclusters for RDS service.

Create RDS Instance snapshot No (Not supported in v2.0.0)Create snapshot beforestopping RDS instances (doesnot apply to Aurora Clusters).

Tag Configuration

Instance Scheduler tag name Schedule Name of tag to use forassociating instance scheduleschemas with service instances.

Apply tags after the instancesare started.

ScheduleMessage=Startedon {year}/{month}/{day}at {hour}:{minute}{timezone}

Comma separatedlist of tag names andvalues on the formatname=value,name=value,..that are set on stoppedinstances.

Apply tags after the instancesare stopped.

ScheduleMessage=Stoppedon {year}/{month}/{day}at {hour}:{minute}{timezone}

Comma separatedlist of tag names andvalues on the formatname=value,name=value,..that are set on stoppedinstances.

Log Configuration

Log retention days 30 Retention days for schedulerlogs.

Enable debug level Logs No Turn on debug level logging inCloudWatch logs.

6. Choose Next.

7. On the Options page, choose Next.

8. On the Review page, review and confirm the settings. Check the box acknowledging that thetemplate will create AWS Identity and Access Management (IAM) resources.

9. Choose Create to deploy the stack.

You can view the status of the stack in the AWS CloudFormation console in the Status column. Youshould receive a CREATE_COMPLETE status in approximately five minutes.

18

Page 23: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideStep 2. Configure periods

Step 2. Configure periodsWhen you deploy the AWS CloudFormation template, the solution creates an Amazon DynamoDB tablethat contains sample period rules and schedules that you can use as a reference to create your owncustom period rules and schedules.

To create a period rule, you can use the Amazon DynamoDB console, the scheduler CLI, or the AWSCloudFormation custom resource that you can create. For details about this stack resource type, refer toCustom resource (p. 35).

NoteIf you use the custom resource to create a period, you must not use the DynamoDB console orscheduler CLI to delete or modify that period. If you do, you will create a conflict between thestored parameters in the stack and the values in the table. Also, do not use periods configuredusing the custom resource in schedules created using the DynamoDB console or the schedulerCLI.

To create a period rule in DynamoDB, modify one of the periods in the configuration table(ConfigTable). To create a period in the scheduler CLI, use the applicable commands (p. 25). Tocreate a period using the custom resource, add the applicable fields to the solution’s custom resource.

For an example period configuration, refer to Sample schedule (p. 37).

Step 3. Configure schedulesTo create a schedule, you can use the Amazon DynamoDB console, the scheduler CLI, or the AWSCloudFormation custom resource that you can create. For details about this stack resource type, refer toCustom resource (p. 35).

NoteIf you use the custom resource to create a schedule, you must not use the DynamoDB console orscheduler CLI to delete or modify that schedule. If you do, you will create a conflict between thestored parameters in the stack and the values in the table.

To create a schedule in DynamoDB, modify one of the schedules in the configuration table(ConfigTable). To create a schedule in the scheduler CLI, use the applicable commands (p. 25). Tocreate a schedule using the custom resource, add the applicable fields to the solution’s custom resource.

For an example schedule configuration, refer to Sample schedule (p. 37).

Step 4. Tag your instancesWhen you deployed the AWS CloudFormation template, you defined the name (tag key) for thesolution’s custom tag. For the Instance Scheduler to recognize an Amazon EC2 or Amazon RDS instance,the tag key on that instance must match the custom tag name stored in the Amazon DynamoDB table.Therefore, it is important that you apply tags consistently and correctly to all applicable instances. Youcan continue to use existing tagging strategies for your instances while using this solution. For moreinformation, refer to Tagging Your Amazon EC2 Resources and Tagging Your Amazon RDS Resources.

On the AWS Management Console, use the Tag Editor to apply or modify tags for multiple resources at atime. You can also apply and modify tags manually in the console.

19

Page 24: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideSetting the tag value

Setting the tag valueWhen you apply a tag to a resource, use the tag key you defined during initial configuration. Set the tagkey to Schedule and set the tag value to the same scheduler name in the Amazon DynamoDB table toschedule your resource. You can also update the scheduler name in the Amazon DynamoDB table.

NoteFor Amazon RDS instances, the tag value can be from 1 to 256 Unicode characters in lengthand cannot be prefixed with "aws:". The string can contain only the set of Unicode letters, digits,white-space, '_', '.', '/', '=', '+', '-' (Java regex: "^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-]*)$"). For moreinformation, refer to Tagging Your Amazon RDS Resources.

Step 5. Launch the remote stack in the primaryaccount and all secondary accounts in the sameRegion

This automated AWS CloudFormation template configures secondary account permissions.

1. Sign in to the AWS Management Console of the applicable secondary account and click the buttonto launch the aws-instance-scheduler-remote AWS CloudFormation template.

You can also download the template as a starting point for your own implementation.

2. The template is launched in the US East (N. Virginia) Region by default. Select the account where theprimary account is launched.

3. On the Select Template page, verify that you selected the correct template and choose Next.

4. On the Specify Details page, assign a name to your remote stack.

5. Under Parameters, review the parameter for the template, and modify it.

Parameter Default Description

Namespace Configuration

Provide the same uniquenamespace value defined inthe hub stack.

Unique identifier used todifferentiate between multiplesolution deployments. Forexample: Dev

Instance Scheduler Hub Account Configuration

Instance Scheduler HubAccount ID

<Requires Input> Instance Scheduler HubAccount number to manageEC2 and RDS Resources in thisaccount.

20

Page 25: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideStep 5. Launch the remote stack in the primary

account and all secondary accounts in the same Region

Parameter Default Description

Set this value to matchhub stack CloudFormationparameter.

No Use this setting to automateremote account enrollment ifusing AWS Organizations.

6. Choose Next.7. On the Options page, choose Next.8. On the Review page, review and confirm the settings. Be sure to check the box acknowledging that

the template will create AWS Identity and Access Management (IAM) resources.9. Choose Create to deploy the stack.

You can view the status of the stack in the AWS CloudFormation console in the Status column. Youshould receive a CREATE_COMPLETE status in approximately five minutes.

21

Page 26: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Additional resources• Amazon Elastic Compute Cloud• Amazon Relational Database Service• AWS CloudFormation• AWS Lambda• Amazon DynamoDB• Amazon CloudWatch• AWS Systems Manager• Amazon EventBridge• AWS Key Management Service• AWS Identity and Access Management• Amazon Simple Notification Service

22

Page 27: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Update the stackIf you have previously deployed the solution, refer to Changes in scheduling v2.0.0 (p. 39) beforeperforming an update.

Many aspects of how the solution start/stop the instances has been changed. Also, some scheduleproperties, such as enforced, retain_running and override are no longer available. If the scenariosyou wish to use for the solution are supported in the latest version, proceed with a stack update.Otherwise, consider installing a new stack and porting the schedules to the new solution and verify if thescenarios are supported.

NoteWe recommend retaining a copy of the previous version’s AWS CloudFormation templateparameters before performing an update.

Use the following procedure to update the AWS Instance Scheduler CloudFormation stack to get thelatest version of the solution’s framework.

1. Sign in to the AWS CloudFormation console, select your existing aws-instance-schedulerCloudFormation stack, and select Update.

2. Select Replace current template.3. Under Specify template:

a. Select Amazon S3 URL.b. Copy the link of the latest template.c. Paste the link in the Amazon S3 URL box.d. Verify that the correct template URL shows in the Amazon S3 URL text box, and choose Next.

Choose Next again.4. Under Parameters, review the parameters for the template and modify them as necessary. Refer to

Step 1. Launch the stack (p. 16) for details about the parameters.5. Choose Next.6. On the Configure stack options page, choose Next.7. On the Review page, review and confirm the settings. Be sure to check the box acknowledging that

the template might create AWS Identity and Access Management (IAM) resources.8. Choose View change set and verify the changes.9. Choose Update stack to deploy the stack.10. Repeat steps 1-9 for your existing aws-instance-scheduler-remote CloudFormation stack.

You can view the status of the stack in the AWS CloudFormation console in the Status column. Youshould receive a UPDATE_COMPLETE status in approximately 15 minutes.

23

Page 28: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideCredentials

Instance Scheduler CLI

The Instance Scheduler command line interface (CLI) allows you to configure schedules and periods, andestimate cost savings for a given schedule.

CredentialsTo use the scheduler CLI, you must have credentials for the AWS CLI. For more information, refer toConfiguration and credential file settings in the AWS CLI User Guide.

Your credentials must have the following permissions:

• lambda:InvokeFunction – To invoke the InstanceSchedulerMain function in the schedulerstack, and to update the schedule and period information in the scheduler configuration databasefrom the command line

• cloudformation:DescribeStackResource – To retrieve the physical resource ID of the AWSLambda function from the stack to handle the CLI request

Requests made by the scheduler CLI and responses are logged in the AdminCliRequestHandler-yyyymmdd log stream.

NoteIf you specify a profile using the profile-name argument, the profile you specify must havethese permissions. For more information about the profile-name argument, refer to CommonArguments (p. 25).

Install the Scheduler CLI1. Download and unzip the scheduler CLI package.

2. In the scheduler-cli directory, run the setup Python script:

python setup.py install

Command structureThe scheduler CLI uses a multipart structure on the command line. The next part specifies the schedulerCLI python script. The scheduler CLI has commands that specify the operations to perform on periodsand schedules. The specific arguments for an operation can be specified on the command line in anyorder.

scheduler-cli <command> <arguments>

24

Page 29: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideCommon arguments

Common argumentsThe scheduler CLI supports the following arguments that all commands can use:

Argument Description

--stack <stackname> The name of the scheduler stack.

ImportantThis argument is required for all commands.

--region <regionname> The Region where the scheduler stack is deployed.

NoteYou must use this argument when the defaultconfiguration and credential files are not installed in thesame region as the solution stack.

--profile-name<profilename>

The name of the profile to use to run commands. If no profile nameis specified, the default profile is used.

--query A JMESPath expression that controls the command output. Formore information on controlling output, refer to ControllingCommand Output from the AWS Command Line Interface in theAWS CLI User Guide.

--help Shows valid commands and arguments for the scheduler CLI. Whenused with a specific command, it shows valid subcommands andarguments for that command.

--version Shows the version number of the scheduler CLI.

Available commands• create-period (p. 25)• create-schedule (p. 27)• delete-period (p. 28)• delete-schedule (p. 29)• describe-periods (p. 29)• describe-schedules (p. 30)• describe-schedule-usage (p. 31)• update-period (p. 32)• update-schedule (p. 32)• help (p. 32)

create-periodDescriptionCreates a period. A period must contain at least one of the following items: begintime, endtime,weekdays, months, or monthdays.

25

Page 30: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideArguments

Arguments--name

The name of the period

Type: String

Required: Yes--description

A description of the period

Type: String

Required: No--begintime

The time when the running period starts. If begintime and endtime are not specified, the runningperiod is 00:00 – 23:59.

Type: String

Constraints: H:MM or HH:MM format

Required: No--endtime

The time when the running period stop. If begintime and endtime are not specified, the runningperiod is 00:00 – 23:59.

Type: String

Constraints: H:MM or HH:MM format

Required: No--weekdays

The days of the week for the period

Type: String

Constraints: Comma-delimited list of abbreviated day names (mon) or numbers (0). Use – to specifya range. Use / to specify every nth day of the week.

Required: No--months

The months of the period

Type: String

Constraints: Comma-delimited list of abbreviated months names (jan) or numbers (1). Use – tospecify a range. Use / to specify every nth month.

Required: No--monthdays

The days of the month for the period

26

Page 31: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideExample

Type: String

Constraints: Comma-delimited list of abbreviated months names (jan) or numbers (1). Use – tospecify a range. Use / to specify every nth day of the month.

Required: No

Example$ scheduler-cli create-period --name "weekdays" --begintime 09:00 --endtime 18:00 --weekdays mon-fri --stack Scheduler{ "Period": { "Name": "weekdays", "Endtime": "18:00", "Type": "period", "Begintime": "09:00", "Weekdays": [ "mon-fri" ] }}

create-scheduleDescriptionCreates a schedule

Arguments--name

The name of the schedule

Type: String

Required: Yes

--description

A description of the schedule

Type: String

Required: No

--periods

A list of running periods for the schedule. If multiple periods are specified, the solution will start aninstance if one of the period rules is true.

Type: String

Constraints: Comma-delimited list of periods.

27

Page 32: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideExample

Required: Yes

--timezone

The time zone the schedule will use

Type: Array of strings

Required: No (If this argument is not used, the default time zone from main solution stack is used.)

Example$ scheduler-cli create-schedule --name LondonOfficeHours --periods weekdays,weekends --timezone Europe/London --stack Scheduler{ "Schedule": { "Name": "LondonOfficeHours", "Periods": [ "weekends", "weekdays" ], "Timezone": "Europe/London", "Type": "schedule" }}

delete-periodDescriptionDeletes an existing period

Arguments--name

The name of the applicable period

Type: String

Required: Yes

ImportantIf the period is used in existing schedules, you must remove it from those schedules before youdelete it.

Example$ scheduler-cli delete-period --name weekdays --stack Scheduler{ "Period": "weekdays"}

28

Page 33: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guidedelete-schedule

delete-scheduleDescriptionDeletes an existing schedule

Arguments--name

The name of the applicable schedule

Type: String

Required: Yes

Example$ scheduler-cli delete-schedule --name LondonOfficeHours --stack Scheduler{ "Schedule": "LondonOfficeHours"}

describe-periodsDescriptionLists the configured periods for the Instance Scheduler stack

Arguments--name

The name of of a specific period you want described

Type: String

Required: No

Example$ scheduler-cli describe-periods --stack Scheduler{ "Periods": [ { "Name": "first-monday-in-quarter", "Months": [ "jan/3" ], "Type": "period", "Weekdays": [

29

Page 34: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guidedescribe-schedules

"mon#1" ], "Description": "Every first Monday of each quarter" }, { "Description": "Office hours", "Weekdays": [ "mon-fri" ], "Begintime": "09:00", "Endtime": "17:00", "Type": "period", "Name": "office-hours" }, { "Name": "weekdays", "Endtime": "18:00", "Type": "period", "Weekdays": [ "mon-fri" ], "Begintime": "09:00" }, { "Name": "weekends", "Type": "period", "Weekdays": [ "sat-sun" ], "Description": "Days in weekend" } ]}

describe-schedulesDescriptionLists the configured schedules for the Instance Scheduler stack

Arguments--name

The name of of a specific schedule you want described

Type: String

Required: No

Example$ scheduler-cli describe-schedules --stack Scheduler

{ "Schedules": [

30

Page 35: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guidedescribe-schedule-usage

{ "Type": "schedule", "Name": "uk-office-hours", “Periods”: [ “office-hours” ], "Type": "schedule", }, { "Timezone": "US/Pacific", "Type": "schedule", "Periods": [ "office-hours" ], "Name": "seattle-office-hours" }, ]}

describe-schedule-usageDescriptionLists all the periods running within a schedule and calculates the billing hours for instances. Use thiscommand to simulate a schedule to calculate potential savings, and running periods after creating orupdating a schedule.

Arguments--name

The name of the applicable schedule

Type: String

Required: Yes--startdate

The start date of the period used for calculation. The default date is the current date.

Type: String

Required: No--enddate

The end date of the period used for calculation. The default date is the current date.

Type: String

Required: No

Example$ scheduler-cli describe-schedule-usage --stack InstanceScheduler --name seattle-office-hours

31

Page 36: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guideupdate-period

{ "Usage": { "2017-12-04": { "BillingHours": 8, "RunningPeriods": { "Office-hours": { "Begin": "12/04/17 09:00:00", "End": "12/04/17 17:00:00", "BillingHours": 8, "BillingSeconds": 28800 } }, "BillingSeconds": 28800 } }, "Schedule": "seattle-office-hours"

update-periodDescriptionUpdates an existing period

ArgumentsThe update-period command supports the same arguments as the create-period command. Formore information on the arguments, refer to the create period command (p. 25).

ImportantIf you do not specify an argument, that argument will be removed from the period.

update-scheduleDescriptionUpdates an existing schedule

ArgumentsThe update-schedule command supports the same arguments as the create-schedule command.For more information on the arguments, refer to the create schedule command (p. 27).

ImportantIf you do not specify an argument, that argument will be removed from the schedule.

helpDescriptionDisplays a list of valid commands and arguments for the scheduler CLI

32

Page 37: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideExample

Example$ scheduler-cli --helpusage: scheduler-cli [-h] [--version] {create-period,create-schedule,delete-period,delete-schedule,describe-periods,describe-schedule-usage,describe-schedules,update-period,update-schedule} ...

optional arguments: -h, --help show this help message and exit --version show program's version number and exit

subcommands: Valid subcommands

{create-period,create-schedule,delete-period,delete-schedule,describe-periods,describe-schedule-usage,describe-schedules,update-period,update-schedule} Commands help create-period Creates a period create-schedule Creates a schedule delete-period Deletes a period delete-schedule Deletes a schedule describe-periods Describes configured periods describe-schedule-usage Calculates periods and billing hours in which instances are running describe-schedules Described configured schedules update-period Updates a period update-schedule Updates a schedule

When used with a specific command, the --help argument shows valid subcommands and argumentsfor that command.

Specific Command Example$ scheduler-cli describe-schedules --helpusage: scheduler-cli describe-schedules [-h] [--name NAME] [--query QUERY] [--region REGION] --stack STACK

optional arguments: -h, --help show this help message and exit --name NAME Name of the schedule --query QUERY JMESPath query to transform or filter the result --region REGION Region in which the Instance Scheduler stack is deployed --stack STACK, -s STACK Name of the Instance Scheduler stack

33

Page 38: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Log filesThe AWS Instance Scheduler creates a log group that contains the default AWS Lambda log files and alog group that contains the following log files:

• InstanceScheduler-yyyymmdd: Logs general scheduler messages• CloudWatchEventHandler-yyyymmdd: Logs general Amazon CloudWatch event rule information• SchedulerSetupHandler: Logs the output of configuration actions• AdminCliRequestHandler-yyyymmdd: Logs requests from the admin CLI• scheduler_ssm_handler-yyyymmdd: Logs the AWS Systems Manager Automation document

workflows• eventbus_request_handler-yyyymmdd: Logs for cross-account events to enroll and de-enroll the

remote accounts

34

Page 39: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Custom resourceYou can use the Instance Scheduler’s AWS CloudFormation custom resource(ServiceInstanceSchedule) to configure schedules and periods. Download the template and updatethe ServiceToken value to the one generated in your instance scheduler stack and use that templateto create a new stack to add schedules and periods. The custom resource uses the same names andsyntax as the fields in the configuration Amazon DynamoDB table. For more information on the fieldsfor schedules, refer to Schedule definitions (p. 6). For more information on the fields for periods, refer toPeriod definitions (p. 8).

When using the custom resource to configure a schedule or period, you must include the account, AWSRegion, and name of the deployed schedule stack in the ServiceToken field.

When you use the custom resource to create a schedule, the name of that schedule is the logical resourcename of the custom resource by default. To specify a different name, use the Name property of thecustom resource. The solution also adds the stack name to the schedule name as a prefix by default. Ifyou do not want to add the stack name as a prefix, use the NoStackPrefix property.

When you use the Name and NoStackPrefix properties, make sure you choose unique schedule names.If a schedule with the same name already exists, the resource will not be created or updated.

The following sample custom resource code shows a schedule (NL-OfficeHours) that contains twoperiods.

AWSTemplateFormatVersion: 2010-09-09 Metadata: 'AWS::CloudFormation::Designer': {}Resources: DutchOfficehours: Type: 'Custom::ServiceInstanceSchedule' Properties: Name: NL-OfficeHours NoStackPrefix: 'True' Description: Office hours in NL ServiceToken: >- arn:aws:lambda:[Region]:[AccountId]:function:[stackName]-InstanceSchedulerMain Timezone: Europe/Amsterdam Periods: - Description: Opening hours on weekdays BeginTime: '08:00' EndTime: '18:00' WeekDays: Mon-Fri - Description: Opening hours in weekend BeginTime: '09:00' EndTime: '17:00' WeekDays: Sat-Sun

Do not use the DynamoDB console or scheduler CLI to delete or modify schedules and periods that wereconfigured using the custom resource. If you do, you will create a conflict between the stored parametersin the stack and the values in the table. Also, do not use periods configured using the custom resource inschedules created using the DynamoDB console or the scheduler CLI.

Before you delete the main Instance Scheduler stack, you must delete all additional stacks that containschedules and periods created using the custom resource because the custom resource stacks containdependencies on the main stack’s DynamoDB table.

35

Page 40: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

In the configuration DynamoDB table, schedules and periods that were configured with the customresource can be identified by the configured_in_stack attribute. The attribute contains the AmazonResource Name of the stack that was used to create the item.

36

Page 41: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuidePeriods

Sample scheduleThe AWS Instance Scheduler allows you to automatically start and stop Amazon Elastic Compute Cloud(Amazon EC2) and Amazon Relational Database Service (Amazon RDS) instances. The following sectionshows how to configure the periods and schedule required to run instances Monday 9 am ET to Friday 5pm ET. Since Monday and Friday are not full days, this schedule includes three periods to accommodate:Monday, Tuesday-Thursday, and Friday.

PeriodsThe first period starts tagged instances at 9 am Monday and stops at midnight. This period includes thefollowing 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 thefollowing 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 andvalues.

Field Value

begintime 00:00

endtime 16:59

name fri-stop-5pm

weekdays fri

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

37

Page 42: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideInstance tag

Field Value

name mon-9am-fri-5pm

periods mon-start-9am,tue-thu-full-day,fri-stop-5pm

timezone America/New_York

Instance tagTo apply this schedule to instances, you must add the Schedule=mon-9am-fri-5pm tag to theinstances. Note that if you changed the default tag name in the AWS CloudFormation Instance Schedulertag name parameter, your tag will be different. For example, if you entered Sked as your tag name, yourtag will be Sked=mon-9am-fri-5pm.

Scheduler CLITo configure the above schedule using the Instance Scheduler CLI (p. 24), use the following commands:

scheduler-cli create-period --stack <stackname> --name mon-start-9am --weekdays mon --begintime 9:00 --endtime 23:59scheduler-cli create-period --stack <stackname> --name tue-thu-full-day --weekdays tue-thuscheduler-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

38

Page 43: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Changes in scheduling v2.0.0This section contains the features that have been removed or modified for the latest version.

AWS Instance Scheduler version 2.0.0 uses SSM Automation documents to perform start and stopactions on the EC2/RDS/RDS clusters. Unlike previous versions, version 2.0.0 only retrieves the schedulesfrom the DynamoDB config table and evaluates which schedules have changed state (starts, stops,and invocations). Then the appropriate runbooks start and stop the instances. In previous versions,the Lambda function would retrieve the schedules, retrieve each individual instance’s current state,and the make a decision based on the rest of the parameters provided in the schedule (enforced,retain_running, override, stop_new_instances).

The following scenarios were introduced in previous versions of AWS Instance Scheduler, which wouldpull the state of the instance and act on the instance/state every five minutes (period that is selected inAWS CloudFormation). In version 2.0.0, this approach of pulling the state of each instance is not used.Instead, the schedule will focus on the schedules, and delegate the automation to Systems Managerrunbooks.

The following scenarios are not supported in version 2.0.0:

1. Schedule configuration attributes enforced, retain_running, override, andstop_new_instances

2. Hibernate option for EC2 instances. This option will be considered for a future update.3. Capability to resize instances based on periods.4. SSM Maintenance Windows: Scheduler no longer supports adding the SSM maintenance windows for

scheduling EC2 instance, as the solution will not interfere with any instance beyond the periods thathave been configured for the schedule this scenario will no longer apply. If you wish to continue to usethe SSM maintenance window, you can use the SSM Automation documents created by the solutionlisted above and start the instances or stop the instance along with any other automations that havebeen configured in Systems Manager. The other workaround is to add the period during which theSSM maintenance window will work on the instance. This solution will start and stop the instance atthe beginning and end of the maintenance window.

5. Amazon RDS SSM maintenance windows. The latest version does not retrieve the state of the RDSinstances.

6. AWS CloudFormation metrics. The instance states are now retrieved or stored by the solution.

39

Page 44: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Identify the AWS Organizations IDTo use the AWS Instance Scheduler with accounts connected to AWS Organizations, you must specifythe AWS Organizations ID when you launch the hub template. The ARN value consists of the AWSOrganizations master account ID and the organization ID. You can find the organization ID in the hubaccount, or you can use the AWS Command Line Interface (AWS CLI) to query the Organization ID.

Use the following steps to get the AWS Organizations ID manually after you have the AWS Organizationsconsole.

1. Sign in to AWS Organizations console from your hub account.2. In the Dashboard, record the Organization ID.

Organization IDo-<org-ID>

To use the AWS CLI to query the ID, use the describe-organization API call. To set up AWS CLI, referto Configuring the AWS CLI in the AWS Command Line Interface User Guide.

40

Page 45: AWS Instance Scheduler

AWS Instance Scheduler Implementation GuideUsing the AWS Management Console

Uninstall the solutionTo uninstall the AWS Instance Scheduler solution, use the following procedure.

Using the AWS Management Console1. Sign in to the AWS CloudFormation console.2. Select this solution’s installation stack.3. Choose Delete.

Using AWS Command Line InterfaceDetermine whether the AWS Command Line Interface (AWS CLI) is available in your environment. Forinstallation instructions, refer to What Is the AWS Command Line Interface in the AWS CLI User Guide.After confirming that the AWS CLI is available, run the following command.

$ aws cloudformation delete-stack --stack-name <installation-stack-name>

41

Page 46: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Collection of operational metricsThis solution includes an option to send anonymous operational metrics to AWS. We use this data tobetter understand how you use this solution to improve the services and products that we offer. Whenturned on, the following information is collected and sent to AWS each time the Instance Scheduler AWSLambda function runs.

The following information is collected and sent to AWS at stack creation or deletion:

• Solution ID: The AWS solution identifier• Unique ID (UUID): Randomly generated, unique identifier for each solution deployment• Timestamp: Data-collection timestamp• Stack Version: The version of the stack that is created or deleted• Status: The status of the stack (stack_created or stack_deleted)• Region: The Region where the stack is deployed

Note that AWS will own the data gathered via this survey. Data collection will be subject to the AWSPrivacy Policy. To opt out of this feature, complete the following steps before launching the AWSCloudFormation template.

1. Download the AWS CloudFormation template to your local hard drive.2. Open the AWS CloudFormation template with a text editor.3. Modify the AWS CloudFormation template mapping section from:

"Send" : {"AnonymousUsage" : { "Data" : "Yes" }},

to

"Send" : {"AnonymousUsage" : { "Data" : "No" }},

4. Sign in to the AWS CloudFormation console.5. Select Create stack.6. On the Create stack page, Specify template section, select Upload a template file.7. Under Upload a template file, choose Choose file and select the edited template from your local

drive.8. Choose Next and follow the steps in Launch the stack in the Automated Deployment section of this

guide.

42

Page 47: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

Source CodeVisit our GitHub repository to download the source files for this solution and to share yourcustomizations with others. The AWS Instance Scheduler templates are generated using the AWS CloudDevelopment Kit (CDK). Refer to the README.md file for additional information.

43

Page 48: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

ContributorsThe following individuals contributed to this document:

• Nikhil Reddy• Lalit Grover

44

Page 49: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

RevisionsDate Change

February 2018 Initial release

July 2018 Added clarification on begintime and endtime; added an exampleschedule configuration

October 2018 Added information on encrypted Amazon EBS volumes; addedclarification on stack name length and Amazon RDS tag restrictions

June 2019 Added information on hibernating Amazon EC2 instances, schedulingRDS instances that are part of an Amazon Aurora cluster, new schedulerCLI arguments, SSM maintenance windows, Parameter Store integration,and clarification on schedules with adjacent running periods

October 2019 Added information regarding the AWS Regions where AWS InstanceScheduler has been validated

March 2020 Bug fixes

June 2020 Clarified time zone information for period rule start and stop times. Forinformation about changes for v1.3.2, refer to the CHANGELOG.md filein the Github repository

September 2020 AWS Cloud Development Kit (AWS CDK) conversion and documentationenhancements. For more information about changes for v1.3.3, refer tothe CHANGELOG.md file in the Github repository

October 2020 Updated the template in Appendix D and updated the documentationfor the Hibernate Field.

April 2021 Updated the SSM Maintenance Window functionality for EC2 instancescheduling, configured solution to work in AWS GovCloud, and bugfixes. For more information about v1.4.0, refer to the CHANGELOG.mdfile in the GitHub repository.

October 2021 Release version 2.0.0: Solution redesigned to use AWS SystemsManager documents to schedule resources, redesign schedule options,remove options enforce, hibernate, retain_running, andchange instance_types. Removed SSM maintenance windowsupport from solution. For more information about v2.0.0, refer to theCHANGELOG.md file in the GitHub repository.

45

Page 50: AWS Instance Scheduler

AWS Instance Scheduler Implementation Guide

NoticesCustomers are responsible for making their own independent assessment of the information in thisdocument. This document: (a) is for informational purposes only, (b) represents current AWS productofferings and practices, which are subject to change without notice, and (c) does not create anycommitments or assurances from AWS and its affiliates, suppliers or licensors. AWS products or servicesare provided “as is” without warranties, representations, or conditions of any kind, whether express orimplied. The responsibilities and liabilities of AWS to its customers are controlled by AWS agreements,and this document is not part of, nor does it modify, any agreement between AWS and its customers.

The AWS Instance Scheduler solution is licensed under the terms of the Apache License Version 2.0available at https://www.apache.org/licenses/LICENSE-2.0

46