This article is meant to be a quick guide that introduces how to get started with Amazon EC2 commandl-ine tools on a MacBook Pro. Most of this information can be found in EC2 API docs, and this is not meant to be a replacement of the documentation, just trying to show the things needed in a clear and smart way.
I assume that you have created an Amazon AWS account already. Once you have your account created, don’t forget to go and create a new X.509 certificate. (It’s under the AWS Access Identifiers page, in the X.509 certificate section near the bottom, click Create New). Once this is done, you need to download the private key file and X.509 certificate.
The only real dependency of the EC2 API tools is Java (at least version 1.5). You can use either Sun JDK or OpenJDK. I chose OpenJDK as it can be installed easily via MacPorts:
joseph-MacBook-Pro:~ joseph$ port list | grep openjdk Warning: port definitions are more than two weeks old, consider using selfupdate openjdk6 @b20 java/openjdk6 openjdk6_bootstrap @b16-r1 java/openjdk6_bootstrap
If you are running Debian (or related distribution), you can easily do this just by running sudo aptitude install sun-java6-jre. For other distributions you can either use their internal packaging mechanism (in case they provide sun-java packages) or just download the binary from sun and install it manually.
EC2 API Tools installation
Next you have to download and install the Amazon EC2 api tools on your Macbook. When it’s installed, the Macbook can be used to start/stop your EC2 servers, and control related resources like disk volume, snapshots, firewalls, machine images, etc.
Extract the EC2 APi tools (it is a zip archive called ec2-api-tools-VERSION.zip), move it under a folder of your preference, and build a soft link to ec2-api-tools.
I like to use /usr/local/ec2-api-tools, and you can use any folder you prefer.
$ sudo mv ec2-api-tools-18.104.22.168 /usr/local $ cd /usr/local; sudo ln -sf ec2-api-tools-22.214.171.124 ec2-api-tools $ ls -l /usr/local total 8 drwxr-xr-x 20 root wheel 680 Jun 28 15:28 bin lrwxr-xr-x 1 root wheel 22 Jul 9 14:21 ec2-api-tools -> ec2-api-tools-126.96.36.199/ drwxr-xr-x@ 7 joseph staff 238 May 25 06:20 ec2-api-tools-188.8.131.52
Also move the private key and X.509 certificate into a proper directory like ~/.ssh/ec2. Those two files look like cert-xxxxx.pem and pk-xxxxx.pem, and change the permission and ownership as your other key files:
$ chown -R `whoami` .ssh/ec2 $ chmod 700 .ssh/ec2 $ chmod 600 .ssh/ec2/*.pem
EC2 Variables Definition
Next we have to export some shell variables. A suggested place to put these lines in is in ~/.profile:
export JAVA_HOME=/Library/Java/Home export EC2_HOME=/usr/local/ec2-api-tools export EC2_PRIVATE_KEY=~/.ssh/ec2/pk-Y3SXMG7CUDS3TSNWP.pem export EC2_CERT=~/.ssh/ec2/cert-Y3SXMG7CUDS3TSNWP.pem export PATH=$PATH:$EC2_HOME/bin
Finally source the file to have the changes actived in your current shell session:
$ source ~/.bashrc
Don’t forget to run your first ec2 command to confirm that it’s working well:
$ ec2-describe-group GROUP sg-6ae67903 096067314635 default default group PERMISSION 096067314635 default ALLOWS tcp 0 65535 FROM USER 096067314635 NAME default ID sg-6ae67903 ingress PERMISSION 096067314635 default ALLOWS udp 0 65535 FROM USER 096067314635 NAME default ID sg-6ae67903 ingress PERMISSION 096067314635 default ALLOWS icmp -1 -1 FROM USER 096067314635 NAME default ID sg-6ae67903 ingress