This is a Python script that brings up a spot EC2 instance (of a specified type, region and maximimum bid), and tags it. It also allows to list and stop active instances.
- Python 2.6 (ish)
- Boto library
A template configuration file is provided in ec2-spot-instance-launcher.cfg.defaults (rename it to ec2-spot-instance-launcher.cfg).
These are some important parameters:
amiUnfortunately you will need to manually find the AMI to use in your regionkey_pairYou will need a named keypair on EC2 for instance creationsecurity_groupDittotagA tag that will be used by the script to identify the instance's purposeuser_dataUser data be passed by the script to instanceuser_data_fileUser data file would be used if user_data is not set. Script would read the file content, and pass the same to instance as user-data
IAM user needs to have access to a number of EC2 API calls, I believe they are:
- DescribeInstances
- DescribeSpotPriceHistoryRequest
- DescribeSpotInstanceRequests
- RequestSpotInstances
The script is written in a fairly platform agnostic way but it's only been tested on Mac OSX.
First connect should go something like:
python main.py Spot price is 0.02... below maximum bid, continuing Spot request created, status: open Waiting for instance to be provisioned (usually takes 1m to be reviewed, another 2m to be fulfilled) ... . . . Instance is active. Tagging instance... Done. Waiting for server to come up ... . . . . Server is up!
Subsequent connects:
python main.py Instance exists already, we will not be provisioning another one Waiting for server to come up ... Server is up!
Terminating (and detagging) the instance:
python main.py stop Terminating i-0a1b1930 ... done.
Most code comes from spot-ec2-proxifier project