Install MongoDB on Amazon 64-bit Linux

First we need to get an EC2 instance up and running using 64-bit Amazon Linux. I like to do this from their command line tools commonly known as their CLI. You can also do this from their console. Here we indicate that we want to use a small instance in the US East 1a data center.

ec2-run-instances ami-1624987f -k KO_Keypair --instance-type m1.small -z us-east-1a

This will take a few minutes to get this guy up and running. I look for running instances by issuing this command.

ec2-describe-instances | grep INSTANCE | grep running

Once the instance is up and running, I ssh into the machine.

ssh -i AWS_KEY_FILE ec2-user@MACHINE_NAME.compute-1.amazonaws.com

Let’s udpate all of the software on the machine and make sure that we have modern versions of everything. This step is not necessary and you should probably skip it if you are just having fun.

sudo yum update

Let’s add the 10gen repo to Yum. This will enable us to download packages from the people who manage MongoDB.

sudo vi /etc/yum.repos.d/10gen.repo

Insert the following within vi. If you don’t know vi, then type i to insert text, then paste this in there, and then hit ESC to exit edit mode and then :wq ENTER to write and quit.

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0

Now use yum package manager to install MondoDB.

sudo yum install mongo-10gen-server mongo-10gen

Let’s create a directory for Mongo to put stuff.

sudo mkdir -p /data/db/

Check out the help on Mongo so you can see what to do.

sudo mongod --help

Ok, now let’s run the Mongo database in the background.

sudo mongod &

Now we can run the interactive shell and check it out.

mongo
> db.people = { 'firstName':'Michael','lastName':'Connor' }
Thu Jul 18 20:54:43.915 [conn1] build index test.people { _id: 1 }
Thu Jul 18 20:54:43.916 [conn1] build index done.  scanned 0 total records. 0.001 secs
> db.people.find()
{ "_id" : ObjectId("51e856137213983dec659177"), "firstName" : "Michael", "lastName" : "Connor" }
exit

That’s it. If you wanna run Mongo in production then ignore this entire post and go to the 10gen website and read about RAID disks and other real world production issues. This is just for fun. Oh, one last thing. If you want to have Mongo continue to run after you log out you will need to run nohup before logging out.

nohup

Get node.js up and running in AWS EC2 by building from source

First we need to get an EC2 instance up and running using 64-bit Amazon Linux. I like to do this from their command line tools commonly known as their CLI. You can also do this from their console. Here we indicate that we want to use a small instance in the US East 1a data center.

ec2-run-instances ami-1624987f -k KO_Keypair --instance-type m1.small -z us-east-1a

This will take a few minutes to get this guy up and running. I look for running instances by issuing this command.

ec2-describe-instances | grep INSTANCE | grep running

Once the instance is up and running, I ssh into the machine.

ssh -i AWS_KEY_FILE ec2-user@MACHINE_NAME.compute-1.amazonaws.com

Let’s udpate all of the software on the machine and make sure that we have modern versions of everything.

sudo yum update

Let’s grab all the dependencies we need to build and operate node.

sudo yum install gcc-c++ make openssl-devel git

Now we are going to make a directory so we can download and build node.

mkdir ~/node
cd ~/node

Let’s download the most recent version of node and extract it into the ~/node directory

curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1

Configure the build for this operating system and environment.

./configure

Now we build node. grab some coffee. this will take a while (20 min or so). When it’s done we will install it.

make
sudo make install

Let’s kick the tires to make sure everything worked. You can CTRL-C twice within the node console to exit.

[ec2-user@ip-10-170-61-122 ~]$ node
> console.log('it worked');
it worked
undefined
>

Let’s clean up the node build directory now that everything has been installed.

sudo rm -rf ~/node

Ok, we’re done but that was kind of a pain. Let’s save this machine so we can resurrect it later and use node without going through all of that hassle. Amazon has a doc on this here.

ec2-create-image -n "AWS Linux 64-bit EBS with Node.js v0.10.13" i-YOUR_MACHINE_INSTANCE_HERE

AWS will return the name of the AMI so you can use that the next time you want to spin up node. If you want a new version of node you will have to start from scratch. Rats!!!!

Now the next time you want a machine like this with node installed you can spin it up with ease. And all of the software will be pretty much up to date so you won’t have to download as many security patches.

How to get node.js running in Amazon EC2 using npm

I spent a while trying to figure out how to elegantly install node.js and npm in EC2 with Amazon Linux using an rpm package manager like yum.  Node.js takes 30 minutes to compile on a micro instance so if you plan to use cloud-formation or spin up new instances to handle load, you need to install with a package manager.

The first thing you have to do is create a machine.  I created a 64 bit micro instance of Amazon.  You can also do this through the console but I prefer the CLI.

ec2-run-instances ami-1624987f -k YOUR_KEYPAIR_HERE --instance-type t1.micro -z us-east-1a

Then I find out the CNAME of the machine.

ec2-describe-instances | grep running

Then login to the machine.

ssh -i YOUR_KEYPAIR_FILE_HERE ec2-user@YOUR_MACHINE_ADDRESS_HERE.compute-1.amazonaws.com

There is a project on git called node-npm that has a good wiki on how to build the node.js package.  Now that you are into the machine, install the stuff we need for nodejs-rpm and the build process.

yum install rpm-build rpmdevtools openssl-devel zlib-devel redhat-rpm-config

Then get the nodejs-rpm project and move to that directory.

git clone https://github.com/kazuhisya/nodejs-rpm
cd nodejs-rpm

And then build the thing.

rpmdev-setuptree
spectool -g -R nodejs.spec
rpmbuild -ba nodejs.spec

It will produce your RPM files.

/home/ec2-user/rpmbuild/RPMS/x86_64/nodejs-debuginfo-0.8.16-2.amzn1.x86_64.rpm
/home/ec2-user/rpmbuild/RPMS/x86_64/nodejs-0.8.16-2.amzn1.x86_64.rpm
/home/ec2-user/rpmbuild/RPMS/x86_64/nodejs-binary-0.8.16-2.amzn1.x86_64.rpm

I then copied nodejs-0.8.16-2.amzn1.x86_64.rpm over to an S3 bucket so that I could install them directly the next time I built a machine.

Now I can just create a new machine and install node via yum.

sudo yum install --nogpgcheck https://s3.amazonaws.com/YOUR_BUCKET/nodejs-0.8.16-2.amzn1.x86_64.rpm

Chatter SAML oAuth Sequence Diagram

This is a sequence diagram of what it takes to implement oAuth with Chatter / SalesForce if you are running SAML in your Enterprise.  This is truly nasty.  Surprisingly, all of these interactions happen fairly quickly and reliably.  The calls to Chatter from the application are via the REST API.

Chatter SAML oAuth

Chatter SAML oAuth Sequence Diagram