Amazon Elastic Compute Cloud (EC2) is the Amazon Web Service you use to create and run virtual machines in the cloud (we call these virtual machines 'instances'). This step-by-step guide will help you successfully launch a Linux virtual machine on Amazon EC2 within our AWS Free Tier.
Launching a Virtual Machine with AWS Requires an Account
Create a Free Account in MinutesAWS Free Tier includes 750 hours of Linux and Windows t2.micro instances each month for one year. To stay within the Free Tier, use only EC2 Micro instances.
a. Click here to open the Amazon EC2 console and then click Launch Instance to create and configure your virtual machine.
You are now in the EC2 Launch Instance Wizard, which will help you configure and launch your instance.
a. With Amazon EC2, you can specify the software and specifications of the instance you want to use. In this screen, you are shown options to choose an Amazon Machine Image (AMI), which is a template that contains the software configuration (e.g. an operating system, an application server, and applications). From an AMI, you launch an instance, which is a copy of the AMI running as a virtual server in the cloud.
For this tutorial, find Amazon Linux AMI and click Select.
b. You will now choose an instance type. Instance types comprise of varying combinations of CPU, memory, storage, and networking capacity so you can choose the appropriate mix for your applications. For more information, see Amazon EC2 Instance Types.
The default option of t2.micro should already be checked. This instance type is covered within the Free Tier and offers enough compute capacity to tackle simple workloads. Click Review and Launch at the bottom of the page.
d. On the next screen you will be asked to choose an existing key pair or create a new key pair. A key pair is used to log into your instance (just like your house key is used to enter your home). Select Create a new key pair and give it the name MyKeyPair. Next click the Download Key Pair button. Be sure to save the key pair in a safe location on your computer.
Windows users: We recommend saving your key pair in your user directory in a sub-directory called .ssh (ex. C:\user\{yourusername}\.ssh\MyKeyPair.pem).
Note: You can't use Windows Explorer to create a folder with a name that begins with a period unless you also end the folder name with a period. After you enter the name (.ssh.), the final period is removed automatically.
Mac/Linux users: We recommend saving your key pair in the .ssh sub-directory from your home directory (ex. ~/.ssh/MyKeyPair.pem).
Note: If you don't remember where you store your SSH private key (the file you are downloading), you won't be able to connect to your virtual machine.
After you have stored your key pair, click Launch Instance to start your Linux instance.
Note: It will take a few minutes to launch your instance.
f. Make note of the Public IP address of your AWS instance, you will need this to connect to the instance in Step 2 part c.
Note: If your instance is still starting up, the Public IP address may not be shown yet. The Instance State column will show you if the instance is running yet, and the Status Checks column will tell you if the instance has passed the 2 checks to make sure it is done provisioning. You can refresh these values by pressing the refresh button on the right just above the table.
After launching your instance, it's time to connect to it.
Windows users: Select Windows below to see instructions for installing Git Bash.
Mac/Linux user: Select Mac / Linux below to see instructions for opening a terminal window.
c. Use SSH to connect to your instance. In this case the user name is ec2-user, the SSH key is stored in the directory we saved it to in step 2 part d, and the IP address is from step 2 part f. The format is ssh -i {full path of your .pem file} ec2-user@{instance IP address}.
Windows users: Enter ssh -i 'c:\Users\yourusername\.ssh\MyKeyPair.pem' ec2-user@{IP_Address} (ex. ssh -i 'c:\Users\adamglic\.ssh\MyKeyPair.pem' ec2-user@52.27.212.125)
Mac/Linux users: Enter ssh -i ~/.ssh/MyKeyPair.pem ec2-user@{IP_Address} (ex. ssh -i ~/.ssh/MyKeyPair.pem ec2-user@52.27.212.125)
Note: if you started a Linux instance that isn't Amazon Linux, there may by a different user name that is used. common user names include ec2-user, root, ubuntu, and fedora. If you are unsure what the login user name is, check with your AMI provider.
You'll see a response similar to the following:
The authenticity of host 'ec2-198-51-100-1.compute-1.amazonaws.com (10.254.142.33)' can't be established. RSA key fingerprint is 1f:51:ae:28:df:63:e9:d8:cf:38:5d:87:2d:7b:b8:ca:9f:f5:b1:6f. Are you sure you want to continue connecting (yes/no)?
Type yes and press enter.
You can easily terminate the instance from the EC2 console. In fact, it is a best practice to terminate instances you are no longer using so you don’t keep getting charged for them.
Now that you have learned how to launch, configure, connect, and terminate an instance in the cloud, you can progress to the next tutorial where you will learn how to register a domain name and attach it to an instance. This will allow your end users to always find your application or website.