Deploying node.js on Amazon EC2

After nearly a month of beating my head against the wall that is hosted node.js stacks — with their fake beta invites and non-existent support — I decided it was time to take matters into my own hands. Amazon Web Service (AWS) offers 12 months of a micro instance for free (as in beer) with 10 GB of disk and 613 MB of memory. This is perfect for an acceptance server running node. All you need to do is sign up with a new email address and provide a credit card. Totally worth it. After 12 months, the price will jump to roughly $15 a month.

I’m a huge fan of Debian and it’s progeny Ubuntu. The guys over at http://www.alestic.com/ do a great job of providing Amazon Machine Images (ami) that are production ready. I choose to use Ubuntu 10.04 LTS because it will be supported until April of 2015. The 64 bit ami for the us-east region is ami-63be790a. Feel free to choose one that best suits your needs.
You will want to setup your default Security Group (the AWS firewall) to allow inbound port 22 and 80 at a minimum (read this for more information). After your instance is up and running, download the ssh identity file (*.pem) and ssh to your new server as the ubuntu user.
ssh -i <identity>.pem ubuntu@ec2-127-0-0-1.compute-1.amazonaws.com

At this point you will want to update your package list and perform all the upgrades for security purposes.
$ sudo apt-get update
$ sudo apt-get upgrade -y

Shortly we can get down to the business at hand but first we need to install a few build tools.
$ sudo apt-get install build-essential libssh-dev git-core -y

You will need to setup inbound and outbound ssh keys for github and teamcity. Add your teamcity id_rsa.pub to /home/ubuntu/.ssh/authorized_keys on the EC2 server and copy your teamcity id_rsa to /home/ubuntu/.ssh/id_rsa as well.

For process management I decided to try out bluepill because I’ve found monit to be unruly and I’m sorta in like with ruby. Here is the acceptance.pill:

Now we just need to load up the configuration on the server:
$ bluepill load acceptance.pill

You can run a cap acceptance deploy from your dev machine or your CI server and the new code will go out and your node.js process will be restarted. You might have to tweak your authorized_keys to make that happen though. Enjoy.

Carbon Five is a full service software consultancy that helps startups and established organizations design, build, and ship awesome products. If you have a project you’d like us to take a look at, or are interested in joining our team, please let us know.