Categories
Coding Hardware

Tips Using Amazon EC2

When I started using Amazon’s EC2 service, I found it hard to gather all the info I needed. There was no easy guide that provided all the steps in an easy format. So, here are some tips I hope some might find helpful. I am interacting with EC2 from a Linux system, so my tips are from that viewpoint.

I assume you have already done the basics, like created your developer account (and know your secret key), and installed the command line tools.

Note that you will need Java installed on your system for the tools to function.

You can find the official EC2 docs here.

Now, on to my tips!

Find A Starter Image

You can browse the images at Amazon via the command :

% ec2-describe-images

You’ll see a bunch of images that are out there, in different UNIX flavors, and some with LAMP already installed. I found that whatever you pick, you’ll want to do your own package installs anyway, so just pick a baseline that you like, i.e. Ubuntu or Redhat or whichever you feel comfortable.

Note that you need the AMI string of your choice to continue. Not only will you see a number of Amazon created AMI’s, but other folks have created some public AMIs that you can choose from. Here are some AMIs for Ubuntu you can check out.

Choose A Server Size

Note that EC2 provides a small, large, and extra-large version your can use. I’ve found that the small instances are incompatible with the the large and XL, so be careful! You should start with the large if you plan on any expansion whatsoever.

So when you are ready to create an instance, you’ll need to specify the size (m1.large or m1.xlarge) on the command line otherwise it will default to small, i.e.:

% ec2-run-instances ami-20b65349 -k gsg-keypair -t m1.large

You’ll need to create a gsg-keypair file first of course. This is described nicely in the command line docs, you’ll use “ec2-create-keypair”.

Note that you can apply a firewall to your instance via the “-g <name>” option, where you define a group with the name of “<name>”. You can see what groups you have via:

% ec2-describe-group

You can create these groups using commands like:

% ec2-authorize mygroup -P tcp -p 22 -s 0.0.0.0/0

Access Your Instance

After you run an instance, you can check on the progress via:

% ec2-describe-instances

And you can provide the instance name also, e.g.

% ec2-describe-instances i-be9237aaa

Then you can SSH into it when it is ready by using the domain name it returns, e.g.

% ssh -i gsg-keypair root@ec2-67-200-1-123.z-1.compute-1.amazonaws.com

Customize Your Instance

You should now make sure your instance has all the packages you want, and configure them how you like. I install the latest Apache, MySQL, PHP, Perl, etc, and edit all the configuration files to my liking.fone

Make sure you stay in “/”, and do not use “/mnt” since this will go away if you reboot and won’t be saved when you save your instance.

If you need more space, you can use the extra storage service from Amazon although I have not done that at this point.

When you have everything the way you like it, you should save your instance. You will use ec2-bundle-vol to create the image, and ec2-upload-bundle to upload it to Amazon’s storage service.

You’ll need your secret key, access key, cert key, user id and a sample command set is as follows. You will run these from your Amazon instance (where real keys and numbers are replaced by X’s and fake numbers):

amazon% ec2-bundle-vol -d /mnt -k pk-XXXXXXX.pem -c cert-XXXXXXX.pem -u 432132132132 -s 1536
amazon% ec2-upload-bundle -b my_image_name -m /mnt/image.manifest.xml -a XXXXXXX -s XXXXXX

Once it is uploaded, you will need to now register it as an AMI image you can access later. You need to do this command from your local host:

% ec2-register my_image_name/image.manifest.xml

This will output your AMI string that you need to note so you can use it later to use your new instance on new Amazon servers.

Cleanup When Done

Don’t forget to make sure you terminate instances you don’t need to use anymore, or you will continue to be charged for them! Run “ec2-describe-instances” to see what you are running, and then you can use “ec2-terminate-instances” with the instance string as an argument to remove them.

Leave a Reply

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