An application for light scheduling of EC2 instances.
JavaScript
Switch branches/tags
Nothing to show
Latest commit e051a52 Mar 4, 2014 @tsbgarner tsbgarner Update README.md
Permalink
Failed to load latest commit information.
libs
.gitignore
LICENSE.md
README.md
app.js
package.json
schedule.ini.sample

README.md

EC2 Scheduler

A lightweight command-line based utility for scheduling EC2 instances.

Copyright 2014 ThinkSpatial
Authored by Brett Garner brett.garner00@gmail.com

The EC2 Scheduler is a JavaScript application built on Node.js. It uses the Amazon Web Services Command Line Interface to query, start and stop instances. It is also used to assign any required Elastic IP addresses.

The following npm modules are used:

Components required

The following components are required by the EC2 Scheduler.

Configuring the AWS-CLI

You must correctly configure the AWS-CLI with your IAM access key id and access key from the command line.

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

The default region name is not important as the scheduler requires instance regions to be specified in the configuration file. It IS important that the default output format be json.

Installing

  1. Obtain a copy of the EC2 Scheduler source by cloning, downloading or forking the GitHub repo.
  2. Whilst there is no need to compile the source, the required modules need to be installed. To do this, you should navigate to the root scheduler directory and type:
$ npm install

This will install each of the required modules into the npm_modules/ directory.

Configuring the EC2 Scheduler

The scheduler requires a configuration file to be provided on launch. The configuration file is where all global, email and instance settings are configured, to be acted upon by the scheduler.

A sample schedule is provided inside the repository named schedule.ini.sample.

Currently the configuration allows three different header tags, marked by surround square brackets.

  1. [OPTIONS]
  2. [EMAIL]
  3. [INSTANCE]

[OPTIONS]

The options tag specifies the section of the configuration file where global process settings are specified. The settings here affect the process as a whole. Any changes to this section require the process to be restarted to take effect. Only one options section should be specified in the configuration file. The section in the sample looks like:

[OPTIONS]
interval_ms = 20000
process_email = admin@email.com

interval_ms - The length of time in milliseconds that the process sleeps before checking whether instances should be acted upon again. Default: 10000
process_email - The email address to send an email to if an uncaught exception occurs.

[EMAIL]

The email tag specifies the section of the configuration file where SMTP server settings are specified. The settings here affect all emails sent by the process. Any changes to this section require the process to be restarted to take effect. Only one options section should be specified in the configuration file. The section in the sample looks like:

[EMAIL]
email = username@email.com
password = emailpassword
smtp_host = smtp.email.com
ssl = true

email - The email address to send emails from.
password - The password for authentication with the selected email.
smtp_host - The SMTP server url.
ssl - Whether to use SSL or not.

[INSTANCE]

The instance tag specifies the section of the configuration file where EC2 instance and schedule settings are specified. Each instance tag affects a single instance. Multiple instance sections can be specified, and is required to support scheduling of multiple EC2 instances. Instance settings can be updated on the fly whilst the process is running without requiring the process to be restarted. The section in the sample looks like:

[INSTANCE]
name = Test
instance_id = i-1aa1aa1a
region = ap-southeast-1
elastic_ip = 10.10.10.10
uptime = Monday,18:30-Monday,18:40
error_email = admin@email.com
event_email = admin@email.com
disabled = false

name - A name for this instance so that it can be easily identified in the configuration file. This does not have to match the name tag of the instance.
instance_id - The id of the instance. The id is unique and must match the instance id that can be found in the AWS dashboard for this particular instance.
region - The region this instance belongs to. Note: Do not append minor region letters (eg ap-southeast-2a) as these are not required and will cause the scheduler to malfunction.
elastic_ip - An elastic IP to assign to this instance. Note: The IP must currently be allocated and available to this AWS account.
uptime - The start and stop time for the instance for a particular uptime. There can be multiple uptime tags per instance, and they may collide without issue. Uptime is specified in the format (Start Day),(Start time)-(Stop Day),(Stop time) and times must be provided in 24 hour format.
error_email - The email address to send alert emails to if there is an error when scheduling this instance.
event_email - The email address to send alert emails to whenever the state of an instance is changed (start, stop, assign ip).
disabled - An optional setting, that when set to true, will cause the scheduler to ignore this instance each interval.

Launching

The scheduler is started by navigating to the root directory of the repository and typing the following on the command line:

node app (path to configuration file)

License

Please see LICENSE.MD for license information.