AWS EC2 Instance

Servers, the heart of our modern connected world. Computers which are opened up to the internet, allowing to communicate with people or other machines. They are serving websites, scripts or databases. Typically servers are stored in huge data centres which are owned by big companies for their own purpose or for renting them to the public. If you for example have planned to create an online store to sell some stuff, you would reach out to one of these data centres and rent one or more server with an annually contract and they provide you access to the machines. In times of cloud computing there is a much more flexible opportunity. With the pay what you use concept, it is very easy to spin up a server in just minutes and shut it down whenever you want. In AWS the described service is called Amazon Elastic Compute Cloud or EC2. And they are probably the reason why you are interested in cloud computing. So let’s have a look at the different configuration options and create a sample server afterwards!

Instance Types

With EC2 you choose your hardware from a broad set of preconfigured options. For example, your instance has a number of virtual CPUs and specific amount of RAM. Some instances also include other types of hardware resources like high-performance local disks, graphic cards or field-programmable gate arrays (FGPAs). Instance types are also grouped into instance families to help you choose the appropriate instance for your application.

EC2 Instance Family For Applications that require…
General purpose A balanced mix of CPU, RAM, and other resources
Compute optimized A high amount of CPU, such as high-performance web servers, scientific modeling, and video encoding
Memory optimized A large amount of RAM, such as in-memory databases and distributed web scale in-memory caches
Storage optimized A A large amount of storage and input/output (I/O) throughput, such as data warehousing, analytics, and big data distributed computing
Accelerated computing Dedicated Graphics Processing Unit (GPU) or Field Programmable Gate Array (FPGA) resources, such as 3D rendering, deep learning, genomics research, and real-time video processing


EC2 instances have the possibility to create persistent storage volumes with the Amazon Elastic Block Store (Amazon EBS) service to provide block store devices for your instance. Block storage is a form of cloud storage that is used to store data, often on storage area networks (SANs). Data is stored in blocks, with each block stored separately based on the efficiency needs of the SAN. Each block is assigned a unique address, which is then used by a management application controlled by the server’s operating system to retrieve and compile data into files upon request. Block storage offers efficiency due to the way blocks can be distributed across multiple systems and even configured to work with different operating systems.

Persistent Storage

For Amazon EC2 instances, Amazon EBS provides persistent block storage. Similar to a hard drive, block storage volumes provide read/write access at a block level and can be formatted with a file system. Also similar to a hard drive, you can attach each EBS volume to a single instance at a time. Amazon EBS is suitable for installing operating systems and applications and for data that you want to store persistently. You can increase the size of volume later.

Temporary Storage

Some instance types allow you tow mount instance store volumes to your EC2 instance. An instance store volume is suitable for high-performance storage of caches or temporary files and for use cases in which your application already replicating the data to other locations. This storage can have a high read/write performance because it is physically attached to the machine that runs the instance. However, your data persists only while the instance is running. If you stop or reboot the instance, the data will get deleted! Rebooting will keep your data.

Amazon Machine Image (AMI)

EC2 instances require an operating system and the configuration of the attached storage volumes. An Amazon Machine Image (AMI) provides the template for the OS and applications on the root volume of your instance. AWS provides a variety of AMIs. Paid AMIS have software licences included and are available in the AWS Marketplace, such as Windows Servers). The cost of software licensing may be included in the hourly rate of the instance. You can also create your own AMIs. Each AWS Region maintains its own listing of AMIs.

Network Interfaces

Each EC2 instance is assigned a primary network interface that is associated with a subnet within an Amazon VPC. If not configured by yourself AWS will assign the instance to the default subnet within the default VPC. The instance receives both a private IP address and a public IP address. In addition a security group protects the traffic entering and exiting the network interface. It act as a stateful firewall. To connect to your interface, you must set security group rules to allow the connection. You can attach multiple network interfaces to an instace, each has his own private and public IP address. The number of network interfaces does not affect the network throughput of the instance; the bandwidth available to the instance depends on the instance type and siye, not the number of network interfaces.

Accessing Instances

Linux operating systems can be accessed through SHH, and Windows instances by providing access throguh the Remote Desktop Protocol (RDP). To connect to these services, you must have the appropriate inbound rules on the security group of the instance. To acquire the credentials needed to sign in as the defaul user, you must specify an EC2 key pair when you launch the instance. After you sign in, you can create additional users with the appropriate Linux or Windows tools.

Create an EC2 Instance

To create your own cloud server, navigate to the EC2 service and click on Instances on the left navigation bar. Then hit Launch instances on the top right corner to start the process.

EC2 instance overview - image by author
EC2 instance overview – image by author

Name your instance and choose an operating system. I recommend to use Amazon Linux with t2.micro as instance type as it is part of the free tier. Afterwards create a new key pair with the default configuration and store them somewhere safe. The remaining configurations can be retained as they are. For example opening ports for serving a website can also be changed later on. So hit Create instance! Back in your instance overview you should see now a new entry with your EC2 name. The Instance state column should be on Pending, just wait a minute and refresh the page till the state gets changed to Running.

New EC2 instance - image by author
New EC2 instance – image by author

You can click on the Instance ID now to reach the instance overview page. Here you see several details about the instance, like it’s public IP address, the associated VPC and Subnet. On the top is also a button called Connect, hit it! Then click on connect, to open up a window which connects you to the server via Bash shell. There you can easily configure your system like a typical Linux machine.

Instance connection with AWS Console - image by author
Instance connection with AWS Console – image by author

SSH into your EC2 Instance

In the last step you already established a connection to your EC2 instance through the AWS Console. But usually you want to use your own terminal and ssh into an instance. Therefore you need the previously created key pair, hopefully you stored them somewhere safe! Start it by opening a terminal and cd into your location where you have stored the .pem file which is the key pair. Then move it to the location .ssh, if you do not have that folder, go ahead an create one in your user direction.

mv <key_pair_name.pem> /Users/<user_name>/.ssh/

Then cd into your .ssh location.

cd /Users/<user_name>/.ssh

It is required to change the permissions of the .pem file to avoid a bad permissions error.

chmod 0400 <key_pair_name.pem>

With that you can now connect to your instance via ssh with the following command:

ssh -i <key_pair_name.pem> ec2-user@<instance_public_ip>

If the connection was successful you will see an output like this:

Instance SSH connection - image by author
Instance SSH connection – image by author

Be aware that the instructions are valid for Linux and Mac, if you are using a Windows machine, either use a Bash shell Putty (different connection process).

Leave a Comment

Your email address will not be published. Required fields are marked *