AWS Spot instance

Concept

Compare to on-demand instance which costs about $0.02/h, spot instance price starts from $0.006, almost a third of the other one. Running a micro instance for a month will be only $4.5.

Why so cheap? One possible reason would be, on-demand instances are charged by hour, which means even if you only used it for one minute then stop your instance immediately, you will still be charged for the full hour.

The only drawback for spot instance is that there is no guarantee for server instance to continue running. When market price goes up, spot instance will be terminated. Try to pick a quiet region if you can, e.g., us-east-1b price history seems very stable  0.006/h for a month, even for past 3 months ( only 2 spikes on Apr. 23)

When instance terminated, all data will be lost. Root ebs will be deleted automatically. If state data is needed, an extra ebs can be attached as user-data storage.There are many different posts showing how to attach another ebs during start-up, like coding in rc.d

http://ec2dream.blogspot.ca/search/label/EBS

http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/

but the easiest way is to set it in request, ec2 tool kit only.

ec2-request-spot-instances -p 0.006 -t t1.micro -n 1 -b ‘/dev/sdf=snap-a023dfdf::false’ ami-746fc91d -z us-east-1b -k mykeypaire -g my-group -r persistent

  1. Can not use sda1 (root), otherwise error: snapshotId cannot be modified on root device
  2. /dev/sdx start from a letter >f, in the example it uses b, I encountered an error saying snap id can only be changed on ebs device.
  3. Don’t forget the key-value pair and security group. They are key to access.
  4. -r persistent means repeat request.

Setup OS (environment, tools, your app, etc)

Spot instance should start working for your order immediately after request fulfilled, the perfect solution would be start from your private AMI.

Create AMI

To create an AMI is to request a on-demand instance, setup everything you need, then

  • Option A: created from an existing instance, better to stop the instance before
  • Option B: create an ebs snapshot, from which create a new image.

Write down your image id. then request spot instance. Request can be done through AWS console or ec2 tool kit.

Setup ec2 tool kit

Download zip file from http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368&categoryID=88

Simply following http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/setting-up-your-tools.html

export EC2_HOME=~/tools/ec2…
export JAVA_HOME=/usr

Generate X509 cert following  http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-credentials.html#using-credentials-certificate
upload those 2 files to your work machine under  ~/.ec2 folder

$ export EC2_PRIVATE_KEY=~/.ec2/pk-blahblah.pem
$ export EC2_CERT=~/.ec2/cert-blahblah.pem

Test setup using a command like ec2-describe-regions

It should work.

Those export and path setup can be put into ~/.bash_profile or ~/.bashrc

Manually attach ebs

Created a new ebs 1G

Attach to new instance manually in AWS console
device name will change to /dev/xvdf from /dev/sdf in ubuntu

ebs needs format before mount

sudo mkfs -t ext3 /dev/xvdf
sudo mount -t ext4 /dev/xvdf /home/ubuntu/folder_to_mount

ref: http://yoodey.com/how-attach-and-mount-ebs-volume-ec2-instance-ubuntu-1010

Set trust scp/ssh for rc2 instance on your own VPS

local: ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ”
remote:(~/.ssh) cat id_dsa >> authorized_keys

ref: http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html

Bad news, spot instance is not included in free tier.

All the saving cost export I spent so far seems useless, and I will revisit this post when my 12 month free tier expired.

Advertisements

Re-configure dreamhost evniorment to support Amazon WebService

I was trying to make my dreamhost to support Amazon WebService (aws), the first problem I encountered is, missing libxslt.

Following the instruction here, I managed to install libxslt to my custom location.

Watch out, the link on http://xmlsoft.org/XSLT/downloads.html is actually pointing to libxml2 which doesn’t include libxslt. You want to find the correct link from ftp://xmlsoft.org/libxslt/

 

The next problem is openssl support missing from ruby. I had to re-configure ruby to make it openssl ready. Instruction can be found here.

 

All aws samples passed, then.

With one minor issue left, I got warning when running ruby:

Invalid gemspec in [/home/me/.gems/specifications/openssl-extensions-1.2.0.gemspec]: invalid date format in specification: “2011-11-03 00:00:00.000000000Z”

Hope I can figure this out later.