Architecture Overview - AWS Instance Scheduler

Architecture Overview

Deploying this solution with the default parameters builds the following environment in the AWS Cloud.


        Instance Scheduler architectural overview

Figure 1: Instance Scheduler on the AWS Cloud

  1. The AWS CloudFormation template sets up an Amazon CloudWatch event at a customer-defined interval. This event invokes the AWS Instance Scheduler AWS Lambda function. During configuration, the user defines the AWS Regions and accounts, as well as a custom tag that AWS Instance Scheduler will use to associate schedules with applicable Amazon EC2, Amazon RDS instances, and clusters.

  2. These values are stored in Amazon DynamoDB, and the Lambda function retrieves them each time it runs. You can then apply the custom tag to applicable instances.

  3. During initial configuration of the Instance Scheduler, you define a tag key you will use to identify applicable Amazon EC2 and Amazon RDS instances. When you create a schedule, the name you specify is used as the tag value that identifies the schedule you want to apply to the tagged resource. For example, a user might use the solution’s default tag name (tag key) Schedule and create a schedule called uk-office-hours. To identify an instance that will use the uk-office-hours schedule, the user adds the Schedule tag key with a value of uk-office-hours.

The Lambda function uses AWS Identity Access Management (AWS IAM) for permission requirements for your resources, and AWS Key Management System (AWS KMS) for encryption of the Amazon Simple Notification Service (Amazon SNS topic) and Dynamo DB tables. Each time the solution’s Lambda function runs, it checks the current state of each appropriately tagged instance against the targeted state (defined by one or more periods in a schedule in the instance tag) in the associated schedule, and then applies the appropriate start or stop action, as necessary.

For example, if the Lambda function is invoked on a Friday at 9 am (ET) and it identifies a stopped Amazon EC2 or Amazon RDS instance with a Schedule=office-hours tag, it will check Amazon DynamoDB for the office-hours schedule configuration details. If the office-hours schedule contains a period rule that indicates that the instance should run Monday through Friday from 9 am ET to 5 pm ET, the Lambda function will start that instance.

The Lambda function also records the name of the schedule, the number of instances associated with that schedule, and the number of running instances as an optional custom metric in Amazon CloudWatch (refer to Amazon CloudWatch Metrics).

Note

Stopping an Amazon EC2 instance is different from terminating an Amazon EC2 instance. By default, Amazon EC2 instances are configured to stop, not terminate, when shut down, but you can modify this behavior. Before using this solution, verify that instances are set to stop or terminate as appropriate.