Deploy spot instances (one-time) from the command line
Quickspot has flexible config files that allow you to create and connect to multiple spot-instances. For a user that is going to be using a single spot instance at any point of time, below is a simple workflow
- Configure
~/.config/aws/config.jsonand~/.config/aws/global_config.json - Execute
qs createto create a spot instance qs connectto connect to the instanceqs listto the list set of running instances.- From the EC2-instance, run
sudo shutdown -h nowto terminate the spot instance.
$ pip install appdirs==1.4.4
$ pip install git+https://github.com/rahul13ramesh/quickspot.git- Fetch the
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYfrom the IAM console - Setup credentials and the default zone for
boto3(guide) - Configure
~/.config/aws/global_config.json(global config applied to all instances). TheKeyNameis the name of the private key on AWS whilepem-fileis the path to the file on your machine.tagswill be applied to every instance your create.
{
"aws_access_key_id": "AWS_ACCESS_KEY_ID",
"aws_secret_access_key": "AWS_SECRETE_ACCESS_KEY",
"pem-file": "~/.ssh/laptop",
"KeyName": "laptop",
"tags": [
{
"Key": "owner",
"Value": "rahul"
}
],
"defaultConfig": "config.json"
}- Configure
~/.config/aws/config.json(instance specific config) from the command line.volume-idis the external volume you would like to attach. Set it toNoneif you would like to attach no volume.tagsare applied to only the specific instance created using this configuration file. Supply an empty array if you would like no such tags to be applied
{
"ImageId": "ami-0123450012341234",
"InstanceType": "g4dn.xlarge",
"KeyName": "rahul-laptop",
"SecurityGroupIds": [ "sg-012345abcdef" ],
"Placement": {
"AvailabilityZone": "us-east-1b"
},
"volume-id": "vol-00abscddefghijk",
"tags": [{
"Key": "Name",
"Value": "machine1-g4dn-b"
}]
}Usage:
qs create [<config_file>]
qs connect [<Name_tag>]
qs copyto [<Name_tag>] --src=<src_file> --dst=<dest_file>
qs copyfrom [<Name_tag>] --src=<src_file> --dst=<dest_file>
qs list
qs price
qs (-h | --help)
Arguments:
list List Instances
connect Connect to an active instance
attach Attach a volume
create Create a new spot instance request
copyto Copy from local to EC2 instance
copyfrom Copy from EC2 instance to local machine
Options:
-h, --help Show this screen.Note that qs create will default to using ~/.config/aws/config.json. You
can use another config files as follows:
- Add a file to
~/.config/aws/(For example~/.config/aws/config_machine2.json) - Call
qs create config_machine2 - Make sure to add the tag "Name". This can be used with the
connect, to specify the instance to which you want to connect to.
Note that qs connect will connect to one of the running instance. To connect
to a specific instance, consider using qs connect <Name tag>, where the name
tag is specified in the associated config file (The "Tags" field in ~/.config/aws/config.json)
Run the following, from the command line of the ec2-instance
sudo shutdown -h now