Baby's First Amazon EC2 Instance
Now that Amazon EC2 has been set up, it’s time to create a server instance.
Choose an AMI
Amazon offers their own AMIs in both 32- and 64-bit versions, each backed by either S3 or EBS. They don’t document what distribution they’re based on, but the package management system is YUM, which suggests Red Hat/Fedora or CentOS.
Canonical publishes AMIs of various versions of their Ubuntu distribution, also in 32- and 64-bit versions and with different backing stores. As Ubuntu is derived from Debian, it uses APT as its package management system.
AMIs from both Amazon and Canonical are preloaded with support for CloudInit.
YUM on the Amazon AMIs is configured to use an Amazon-specific package repository stored in S3; bandwidth used to access this repository doesn’t count toward your charged limit. On the other hand, the version of neither the distribution used nor the Linux kernel running is documented, whereas with the Canonical AMIs it is.
Create a new instance
Look up the identifier for the AMI you want to launch, from either
Canonical. Be sure to choose an appropriate region; as The Day Job
is based on the American East Coast, I’m going to use
us-east. Also, for this go-around,
I’m going to use a 32-bit instance from Amazon that uses S3 as a backing store.
About the parameters and their values:
ec2-keypairwith the name of the keypair you generated in the initial setup, if necessary.
Open the firewall for SSH and ICMP connections. Note that these operations are on a
security group (
default by, well, default); once you have done them once for your account,
you shouldn’t need to again. 1
Make sure that the instance is running:
Note that your instance ID (
i-fe56b891), DNS name (
and public IP address (
188.8.131.52) will be different from mine, and the latter two will change
each time you start the instance. I’ll cover how to get a persistent IP address in a later post.
Log in and look around
The Amazon Linux AMIs are preconfigured with a single user account named
ec2-user. Since we
opened up the SSH port, we can log in as this user:
This is a full-fledged Linux system, albeit a little light on the installed packages. 2 You can do all the things you’d expect to be able to do on a Linux system:
…except, apparently, the things requiring root privileges. Not a problem, as
ec2-user has sudo privileges:
Finally, just to prove we have full access to the outside world:
Don’t forget to shut down
As soon as the instance launches, you start racking up charges – granted, at the rate of USD0.085 per hour, more or less. Shut the instance down when you’re done with it, to avoid surprises on your credit card bill later.
First, if you’re still logged into the instance, log out.
Next, terminate the instance: 3
Give it a minute or two, then double-check that the instance is no longer running:
At some point in the near future, this record will be garbage collected, and won’t show
ec2-describe-instances any more.
But it won’t hurt if you do. You’ll just get a warning to that effect. ↩
On purpose. Amazon’s stated intention is to make a small, quick-booting Linux system, and let you add on the stuff you need. ↩
S3-backed instances like this can only be terminated, which means that they will be deleted after they shut down, and any data stored or changed in the instance will be lost. EBS-backed instances can be stopped without terminating, which means they remain known to EC2 and can be restarted again. I’ll show an example of this in a later post. ↩