Spin up your EC2 instance
You have your tools installed, you have your keys, you've picked an AMI and availability zone. Now you're finally ready to create a real Amazon instance. At the command line, enter:
$ ec2-run-instances ami-31814f58 -k my-keypair -t t1.micro -z us-east-1a
Notice I chose a micro instance. Micro instances are free, so they're a great option for trying out the tools.
Connect to your instance
Now that you have a running instance in EC2, you'll want to connect. Let's find out its name:
RESERVATION r-d1a71cc1046997127105 default
ip-10-44-61-104.ec2.internalrunning my-keypair0 t1.micro2012-06-15T13:11:05+0000us-east-1a aki-417d2539monitoring-disabled 188.8.131.52 10.46.63.204ebs paravirtualxen sg-65f4ec0adefault
BLOCKDEVICE /dev/sda1vol-3f1ac253 2012-06-15T13:11:32.000Z
Once you know the IP address to the box, go ahead and connect:
$ ssh -i my-keypair
A few routine tasks
Folks familiar with Linux Volume Manager know that you can easily snapshot a disk volume. In Amazon, snapshots are a powerful facility for creating backups, protecting you from instance failure, and even creating new AMIs from your custom server setups. Look at the
BLOCKDEVICE line above. You'll see the volume ID. That's all you need:
$ ec2-create-snapshot vol-3f1ac253
A few details to keep in mind: Although you can snapshot a running server, some tools will stop your instance in order to snapshot the root volume. This is for extra protection against corruption of the file system. If you're using a journaling file system such as ext3, ext4, or xfs, snapshotting a running system will leave your volume in a state similar to a crashed server. Upon startup, incomplete blocks will be repaired. In the case of a database mount such as MySQL, however, you should issue these additional commands from the MySQL shell:
mysql > flush tables with read lock;
mysql > system xfs_freeze -f /data
For an in-depth explanation of how to do this, see my article, "Autoscaling MySQL on Amazon EC2."
When instances are started, Amazon automatically assigns a new IP address to them. Dynamic addresses are fine for playing around, but you'll undoubtedly want static, global IP addresses for some machines eventually. That's where elastic IP addresses enter the picture; your AWS account comes with a number of these. You can set your new instance with one of these static IPs using a simple command-line call:
$ ec2-associate-address 10.20.30.40 -i i-17086273
You're all set.
Now that you've had a taste of Amazon, you'll want to explore more. With the command-line tools installed and your security keys set up, you have everything you need to go further -- and get comfortable with different instance types, various AMIs, the Availability Zones your instances and volumes are stored in, how load balancers work, and beyond. The further you go, the more you'll appreciate that Amazon's documentation is as copious as its services.
This article, "How-to: Get started with Amazon EC2," originally appeared at InfoWorld.com. Follow the latest developments in cloud computing at InfoWorld.com. For the latest business technology news, follow InfoWorld.com on Twitter.