A lightweight command-line based utility for scheduling EC2 instances.
Copyright 2014 ThinkSpatial
Authored by Brett Garner email@example.com
The following npm modules are used:
- moment - https://github.com/moment/moment
- emailjs - https://github.com/eleith/emailjs
- underscore - https://github.com/jashkenas/underscore
The following components are required by the EC2 Scheduler.
- Node.js - http://nodejs.org/ (Includes npm)
- npm https://www.npmjs.org/
- AWS CLI - http://aws.amazon.com/cli/
- An SMTP server (Optional)
- AWS IAM User with EC2 permissions
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.
- Obtain a copy of the EC2 Scheduler source by cloning, downloading or forking the GitHub repo.
- 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.
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 = firstname.lastname@example.org
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.
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 = email@example.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.
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 = firstname.lastname@example.org event_email = email@example.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.
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)
Please see LICENSE.MD for license information.