Getting started with EC2 on Ubuntu

Amazon is offering 750 hours of a Micro instance for free. This would give you about a month of uptime. Here is a small guide on how to get started.

This guide will take you through the steps:

  1. Sign up
  2. Downlad Keys and Certificates
  3. Create an instance
  4. Connecting to your EC2 Instance with SSH

Sign up

Go to the Amazon EC2 sign up page and sign up for a free account. You can use and existing Amazon account, or create a new one.
Since this is a pay-as-you-go model, they want you to enter your credit card. Because you are signing up for a free account they will notify you by email if your estimated bill goes over 0.00$.

Once you have signed up, you will end up at the EC2 console.
Remember to change your region to something appropriate for you in the top right corner before you start. The available regions are:

  • US East (N. Virginia)
  • US West (Oregon)
  • US West (N. California)
  • EU (Ireland)
  • Asia Pacific (Singapore)
  • Asia Pacific (Tokyo)
  • Asia Pacific (Sydney)
  • South America (São Paulo)

Download Keys and Certificates

Now you want to get all your keys and certificates.
First navigate to the Key Pairs menu (under Networks and Security) in the left side menu. Create a new key-pair, give it an appropriate name, and download it to a folder where you can find it again (e.g. ~/ec2/amazon-ec2.pem)

The next keys you need you can find under your accounts Security Credentials page. Create a X.509 Certificate and download the certificate and private key to your computer (save them in e.g. ~/ec2/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem and ~/ec2/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem).

Make all your keys private:

chmod go-rwx ~/ec2/*.pem

Create an instance

Go to Instances in the EC2 console and click the Launch Instance button. This will start a wizard taking you through seven steps.

Step 1

Select the OS you want (I would reccomend Ubuntu 12.04.3).

Step 2

Choose Micro instance for the free tier.

Step 3-5

All of these will be fine at default settings. Add more storage if you need (default is 8GB, max on a free account is 30GB).

Step 6

Here you want to create a SSH security group and limit the IP-addresses to the IP-adresses of your home or work network.

Step 7

Review and then click Launch

Connecting to your EC2 Instance

Installing the EC2-Api-Tools

To make sure you get the latest most up to date tools add the awstools ppa by running:

sudo apt-add-repository ppa:awstools-dev/awstools
sudo apt-get update

Then install the tools by with:

sudo apt-get install ec2-api-tools

Set up your shell profile

Open up your ~/.bashrc file in a text editor and add the following lines:

export EC2_KEYPAIR=<your keypair name> # name only,  not the file name
export EC2_URL=https://ec2.<c2 region>
export EC2_PRIVATE_KEY=$HOME/ec2/pk-<something>.pem
export EC2_CERT=$HOME/ec2/cert-<something>.pem
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/

Load changes into your shell session

source ~/.bashrc

Logging in with SSH

To see the status of your instances run


You may then run the command

ssh -i <private key file> <username>@<host-name>

to log to the instance specified by host name. The host name you can find in the output of ec2-describe-instance. It looks like something like this "". If you chose ubuntu as OS for your instance the username is ubuntu.

Your private key file is the key-pair private key you downloaded earlier (if you followed the examples literally it would be ~/ec2/amazon-ec2.pem).

If you don't want to remember that ssh command in your head add this to your .ssh/config file:

Host <shortname>
    Hostname <host-name>
    User <username>
    IdentityFile <private key file>
    ForwardAgent yes

Then you can run

ssh <shortname>

to connect.