← Back to the main 'Using Fedora' page.

Create a Fedora Amazon EC2 Instance

This quick and easy tutorial will show you how to create a Fedora EC2 instance.

Preparations

This tutorial assumes you already have an AWS account. AWS is not a free service - it is designed as a pay-as-you-go online service. You can learn more about pricing at http://aws.amazon.com/ec2/pricing/

In this tutorial, we will use euca2ools, a suite of command line tools designed for services like EC2. You can install it simply by typing:

yum install euca2ools

To use the command line tools you first need to obtain access keys for your account. You can find them by going to the AWS management console on the web, clicking your name on the top, followed by Security Credentials, and scrolling down to the section titled Access Credentials.
Make note of the Access Key ID and the Secret Access Key that appears beside it. Both of them should be long sets of alphanumeric characters. Create a file called .iamrc in your home directory that contains those keys in this format:

AWSAccessKeyId=your_access_key_id
AWSSecretKey=your_secret_key

Since euca2ools is designed to work with all AWS-compatible clouds, not just AWS itself, it needs to know which cloud to contact. Create a file called .eucarc in your home directory with the following content to point it toward AWS:

export AWS_CREDENTIAL_FILE=~/.iamrc
export EC2_URL=https://ec2.amazonaws.com/
export S3_URL=https://s3.amazonaws.com/
export EUARE_URL=https://iam.amazonaws.com/
source "$AWS_CREDENTIAL_FILE"
export EC2_ACCESS_KEY=$AWSAccessKeyId
export EC2_SECRET_KEY=$AWSSecretKey
export AWS_ACCESS_KEY=$AWSAccessKeyId
export AWS_SECRET_ACCESS_KEY=$AWSSecretKey

Finally, add these settings to your shell's environment by running:

$ source ~/.eucarc

Choose an EC2 server

Choose an EC2 region to use. Things to consider when choosing a region include its geographic location, the pricing for instances in that region, and whether the image you wish to use is available in that region. You can get a list of regions by running euca-describe-regions, which results in a list such as this:

eu-west-1 ec2.eu-west-1.amazonaws.com
us-east-1 ec2.us-east-1.amazonaws.com
ap-northeast-1 ec2.ap-northeast-1.amazonaws.com
us-west-1 ec2.us-west-1.amazonaws.com
ap-southeast-1 ec2.ap-southeast-1.amazonaws.com

When you choose an EC2 region you can make euca2ools start using it by editing the line that contains EC2_URL in your .eucarc file.

$ export EC2_URL=https://ec2.us-east-1.amazonaws.com/

...and then re-set the settings in your shell's environment:

$ source ~/.eucarc

Creating a key pair

The primary way of logging into Fedora instances is via SSH. Since Fedora instances have no passwords, you need a SSH key pair to log in to them. The private half of this key pair is stored on your computer, while the public half is stored in EC2 so instances can download them as they start. This allows you to securely log into your instances without a password.

You can have multiple key pairs. Each key pair has its own name. Key pairs are specific to each EC2 region.

Choose a name for a new key pair and then use the euca-create-keypair command to create it and write the private key to a file. Be sure to choose a name that is easy to remember.

$ euca-create-keypair mykey > mykey.pem

Note: Key pairs are irreplaceable|EC2 does not store the private halves of key pairs. The time you run euca-create-keypair is the only chance you will have to save a copy of the private key. There is no way to recover a lost private key from EC2.

You can use euca-describe-keypairs to display a list of your keypairs.

$ euca-describe-keypairs
KEYPAIR mykey1 7b:9b:33:cf:bf:12:4d:62:b6:7c:fa:02:f2:f7:bc:59:e3:7e:40:fb
KEYPAIR mykey2 f9:93:1e:73:4b:2e:c1:0d:7f:79:e1:bc:c0:d0:7c:95:32:55:b7:dd

You can use euca-delete-keypairs to delete a keypair. Deleting a keypair does not remove it from instances that are already running; it merely prevents new instances from using it.

$ euca-delete-keypair mykey1

Run an instance

Run a new instance of the image and instance type you chose with euca-run-instances. To be able to log into the new instance, you must also specify the name of the key pair you created earlier. For example, to run a t1.micro instance of the image ami-7f5a063a with a key pair named mykey, run the following command:

$ euca-run-instances ami-7f5a063a -t t1.micro -k mykey
RESERVATION r-4d5ea00a 0123456789ab default
INSTANCE i-910fbbd6 ami-7f5a063a pending 0 mykey t1.micro 2011-10-11T00:00:00.000Z us-east-1c aki-9ba0f1de

The output of euca-run-instances contains the ID of the instance you just started. In the example above, the instance's ID is i-910fbbd6. You will need this ID to use tools that need to refer to the instance.
You can also find the various AMI-IDs for Fedora images for all regions here.

The instance starts in the pending state. When it finished booting it changes to the running state. When you terminate it it changes to the shutting-down and finally terminated states.

Log into the instance

As the instance starts it obtains an IP address from EC2 and changes to the running state. You can check on your instances by running euca-describe-instances, optionally with the ID of the instance in question. When the instance is ready (or nearly ready) to use, euca-describe-instances will display the address you can use to log into it:

$ euca-describe-instances
RESERVATION r-4d5ea00a 0123456789ab default
INSTANCE i-910fbbd6 ami-7f5a063a ec2-204-236-168-22.us-east-1.compute.amazonaws.com ip-10-170-15-23.us-east-1.compute.internal \
running 0 mykey t1.micro 2011-10-11T00:00:00.000Z us-east-1c aki-9ba0f1de

The public address of the instance in this example is ec2-204-236-168-22.us-east-1.compute.amazonaws.com. Other useful bits of information from this command include the availability zone in which the instance is running (us-east-1c) and the time that the instance started.

Once the instance is running you can log into it with ssh. On Fedora's images you should log in as fedora user:

$ ssh -i mykey.pem fedora@ec2-204-236-168-22.us-east-1.compute.amazonaws.com
[fedora@i-910fbbd6 ~]$ cat /etc/fedora-release
Fedora release 20 (Heisenbug)

You can now use the instance as you would use any other computer running Fedora.

When you finish using the instance you should terminate it with euca-terminate-instances to free up resources and reduce costs:

$ euca-terminate-instances i-910fbbd6

Enjoy and share!

Now you know how to setup a Fedora EC2 Instance! Have fun, and be sure to share these tips you learned with others!

← Read about more ways to use Fedora!