One basic concept that escapes most cloud newbies is the fact that you are accessing a remote resource as if it were local; a very basic yet very powerful concept to understand. When think of how to approach development for the cloud, you could simply ask: What would you do if the node you are accessing is right in your own datacenter?
Amazon EC2 provides all you need to create an ecosystem or environment that allows seamless access to a remote virtual environment. One main difference is EC2's auto scaling capability, which automatically increases or decreases the number of running Amazon EC2 instances to match demand. Scaling takes place when a metric's upper or lower boundary threshold is breached for the duration specified by the user's configuration. In essence, you create low and high water marks that if are breached, the number of machine instances (called Amazon machine images or AMIs) changes.
My previous article focused on the basics of the Amazon EC2 cloud offering. In this article, I will discuss how to actually get started with the EC2 infrastructure. Keeping only to EC2 for AWS newcomers, I will not cover other services that Amazon offers such as MapReduce, Database, and Simple Queuing Service. In fact, this article skips over many of the required steps for using EC2; you should use it only as a general beginner's guide.
Accessing Amazon EC2 with REST
There are many ways to access EC2, and in this article I will focus on the most basic and platform-independent way: via REST. There are APIs that do the same thing, but I will leave that for future articles. I want to cover REST first because I can use it as the basis to illustrate how things actually work, even though most times a higher-level programming language is used.
One basic assumption here is that you have an account set up already with the proper credentials.
There are a number of classes of Amazon Machine Images:
- Custom-made ones you make yourself
- Custom-made ones that you pay for
For many grid-type applications (the type I often work with), the vanilla image will do just fine -- after all, all you need to do is compute, right? Right!
So I need to construct a REST request that asks for all the available AMIs.
This message will find and return all the images owned by Amazon. Amazon also provides an authenticator, which you need to use for access every time. You might get something like the following as the result.
<description>Fedora 8 v1 ec2pnp enabled</description>
This completely generic sample basically provides all you need to know about the image. What is important is the
imageId, which Amazon will use as the OS to boot up your instances.