Five Easy Steps to Tag EC2 Instance Using mr.awsome

Are you running 10,30 or 100 instances in your single EC2 Account? How do you identify each one?

There have been lot of questions on how to tag and manage a bunch of EC2 instances. To tell you I’ve been into your situation, after working with several EC2 clients. What a pain to keep track which instance is which.

Existing posts about How-are-admins-managing-their-ec2-ebss-and-snapshots and answers like Tagging-ec2-instances-using-security.

But in some cases, placing a set of instances into a set of groups, would possibly create or block access to the other instances using the same group when trying to change a security settings.

Matt Juszczak describe an example of this problem in his blog here.

Proposed Solution: Set a unique security group for an instance.

PROS:
1. It solves the tagging of each instance
2. Eliminates the possible problem describe above since the current instance is only affected when you try to change it’s security settings.

CONS:
1. Unfortunately, you have to define individual group for each of the instance and that is extra work.
2. Existing instances (especially production instances) cannot make use of this solution unless by launching the production image and remapping Elastic IP.


mr.awsome is a simple tool where you can provision instance and define a unique security to identify each of them, and automatically accessh each instance via ssh. You can define servers, launch them and be able to tell which instance is which whether you will be going to use AWS Console or ElasticFox later. The security groups are defined and used by the instances.

Tested using Ubuntu Jaunty w/ Python 2.6
The Steps:
1. Installation:

$ sudo apt-get install python-setuptools python-dev
$ sudo easy_install mr.awsome 

$ export AWS_ACCESS_KEY_ID=accesskey
$ export AWS_SECRET_ACCESS_KEY=secretkey
$ ssh-add /path-to-/id_rsa-gsg-keypair

2. For your new EC2 Project, a simple directory structure for a project:

 
   ec2-project/
               etc/
                  aws.conf
$ mkdir  -p ~/ec2-project/etc
$ cd ~/ec2-project 

3. Edit the etc/aws.conf and paste the line below (Note: change to use your own keypair)

[securitygroup:webserver1]
description = webserver1 group
connections = 
  tcp 22 22 0.0.0.0/0
  tcp 80 80 0.0.0.0/0

[securitygroup:dbserver1]
description = dbserver group
connections =
  tcp 22 22 0.0.0.0/0
  tcp 80 80 0.0.0.0/0

[instance:webserver1]
keypair = gsg-keypair
securitygroups = webserver1
region = us-east-1
placement = us-east-1a
# we use images from `http://alestic.com/`
# Ubuntu 9.04 Jaunty
image = ami-ccf615a5
  
[instance:dbserver1]
keypair = gsg-keypair
securitygroups = dbserver1
region = us-east-1
placement = us-east-1a
# we use images from `http://alestic.com/`
# Ubuntu 9.04 Jaunty
image = ami-ccf615a5

4. Now we can launch the servers:

$ aws start webserver1 
$ aws start dbserver1 

5. After a while, checking the fingerprint status, you will be able to do:

$ aws status webserver1 
$ aws ssh webserver1 

$ aws terminate webserver
$ aws terminate dbserver1

Dont forget to turn off the instances.

I have been extending the tool and added some basic improvements found here.

The latest update is to be able to run a set of servers in one command, but still be able to tag each instance easily. If you choose to use my updates:

$ git clone http://github.com/cocoy/mr.awsome
$ cd mr.awsome 
$ sudo python setup.py develop
$ cd ~/ec2-project 
$ aws -h

Now you can start your new servers. Tag and identify those instances. As in the old movie Highlander: “There can only be one”.

If you need more customization of the tool or in tagging your 100 instances contact me. 😉

Update: 02-09-20111
With new boto featues added the tagging, mr.awsome need to be change to use that instead of using security group.

6 thoughts on “Five Easy Steps to Tag EC2 Instance Using mr.awsome

  1. Christian Pesch

    > sudo apt-get install python-setuptools

    hangs in an endless loop and resists kill -9 when started with Ubuntu 10.04 on a 34G AWS 2xlarge image. Any ideas how to solve this?

  2. rodney Post author

    I tried it with Ubuntu 10.04 us-east-1 x86 AMI: ami-6407f20d

    sudo apt-get update
    sudo apt-get install python-setuptools python-dev

    It was able to install setup-tools without problems.:)
    Either a missing ‘python-dev’ on the end of your command.

    Let me know how it goes.

  3. Christian Pesch

    Sorry for coming back this late, but I’d like to share my finding since I couldn’t find any hints when googleing.

    There seems to be a problem with Ubuntu 10.04 and 10.10 when you prepare an AMI with an m1.large instance (7,5 GB RAM) and start that AMI on an m2.2xlarge image. And the problem is really that dpkg hangs in an endless select()-loop no matter which .deb package is installed and cannot be stopped with kill -9.

    When I prepared an AMI on an m2.2xlarge image the problem went away.

  4. drtune

    Just a “historical” note for any readers that this tip is obsolete now; Amazon have implemented tagging of instances..

    for i in reservation.instances:
    i.add_tag(“key”, “value”)

Leave a Reply

Your email address will not be published. Required fields are marked *