Creating your first EC2 instance
There are some steps needed in order to successfully create a virtual machine in an EC2 environment.
Step 0: Open the EC2 Instance Launch Wizard
If you haven't already, open the EC2 Instance console at https://console.aws.amazon.com/ec2/v2/home#Instances and click on "Launch Instance"
Step 1: Select a suitable AMI
First, we have to select an Amazon Machine Image (or AMI). This is a virtual machine image with some EC2-specific adaptations. There are two different AMI types: Hardware Virtual Machine (HVM) and Paravirtual (PV).
New instances should use the HVM type when available, this allows them to make use of newer hardware acceleration features. HVM instances used to have performance drawbacks when compared to PV instances, but this is no longer true. Amazon's latest instance types do not support PV AMIs.
AMIs are uniquely identified by a 17-character ID, which is prefixed with "ami-". These IDs are per AWS region, so the same software will have different IDs in different regions.
For our example, which we will run in the AWS region "eu-central-1", we will be using an Ubuntu Server 18.04 HVM AMI with an SSD volume. (Be sure to check your current region and change it, if necessary!)
We chose Ubuntu for this example because it offers recent software and 5 years of support by Canonical.
To find the most recent Ubuntu AMI, navigate to Canonical's "Amazon EC2 AMI locator" and set the appropriate filters to narrow down the number of results:
- Zone: eu-central-1
- Version: 18.04 LTS
- Instance Type: hvm:ebs-ssd
At the time of writing, this results in the AMI ID "ami-029bb09da31cbfdfc"
Step 2: Select an Instance Type
Amazon offers different instance types for differnt types of computing tasks. For our example, we will be using a "t2.nano" instance with two vCPUs and 512 MB RAM. This instance type is eligible for the EC2 free usage tier.
For next steps, be sure not to click on the "Review and Launch" button, but on the "Next: Configure Instnce Details" button.
Step 3: Configure Instance Details
In this step, you can specify the number of instances, network settings and many other options you will probably not need for most use cases.
The option "T2/T3 Unlimited" is not necessary for our purposes and should be deactivated, though, since it would incur costs otherwise.
Step 4: Storage
Storage volumes in EC2 are known as Elastic Block Storage (or EBS) volumes.
The T2 instance type has a 8 GB root volume and no additional storage by default. The size and type of the root volume and additional volumes can be configured in this step.
Because they are designed to be on-demand resources by default, EBS volumes will be deleted when their attached EC2 instance is terminated. If you want to keep the data on a volume, you need to uncheck "Delete on Termination".
Step 5: Tags
Tags are used to make it easier to find specific EC2 resources (instances, EBS volumes, etc.) when there are many different resources in an AWS account. You can ignore this step for now.
Step 6: Security Groups
A Security Group is like a firewall which can be placed in front of an instance.
For example, a very simple web server requires the ports 80 (and 443) to be accessible from the Internet. In a Security Group, this means you need to add rules for "HTTP" and "HTTPS" from "Anywhere".
In order to configure your new instance, you also need to allow SSH access.
If you can, you should always restrict the IP addresses that can access the instance via SSH.
Make sure that you have created all the necessary rules before you start the instance. This will save you a lot of debugging effort later.
Hint: Security Groups can also restrict outgoing traffic.
Step 7: Review and Launch
In this step, you can review the configuration defined in the previous steps.
When you are ready to start the instance, click on the "Launch" button. The newly created instance will boot the AMI and get a public IP address assigned.
Your instance will always get a new IP address when it is restarted.
The only way to prevent this is to reserve an Elastic IP and assign it to your instance. This IP stays the same as long as it is reserved. Elastic IPs are free unless they are not allocated to a running EC2 instance.
After these few steps, you have created your first multi-purpose cloud server on AWS. This could be a perfect starting point for bringing your application into the cloud. We will provide follow-up blog posts which show you how to use the full power of the Amazon Cloud by using scalable serverless API’s like API Gateway, Lamba or Simple Storage Service (S3).