January 13, 2016

AWS – Amazon Elastic Cloud Compute (EC2) overview

EC2 is arguably the most important service available on the AWS platform,  EC2 is used for creating VMs on the AWS platform. These vms are referred to as EC2 “instances“. There are three pricing models available under EC2:


You can find all my latest posts on medium.



  • On-Demand Instances: This lets you pay for computing capacity by the hour with no long-term commitments.
  • Reserved Instances: This reserves an instance’s resource exclusively for your use. You get charged even if you don’t use them. But it garauntees that this resource is available in the given AZ. You can book your instance a period of one month, to up to 3 years. You can also sell it if you don’t need it anymore. You also have an option to ensure this vm runs on the same physical machine throughout the term.
  • Spot Instances – Spot Instances enable you to bid for unused Amazon EC2 capacity. Only recommended to use this for doing things like processing non-production stuff.

You don’t pay for the EC2 while it is switched off.  However you still have to pay for  any EBS devices attached to your EC2 instance.
Later on you will find the aws cost calculator really handy.


EC2 features

  • Autoscaling/elastic
  • highly availablle
  • fault tolerant
  • Tightly integrates with Elastic Load Balancer, so that an ELB can evenly distirbute work to a cluster of servers, that can reside across multiple AZs, within the same region.
  • Tightly integrates with Elastic Block Storage (EBS) – which is how we added network based block devices to the vm.


Instance Types

Since EC2 instance have built in auto-scaling it means that we don’t need to build an 10 CPU vm, where 4 cpus are required for nearly the whole year and only 10 CPU is require during the Christmas period. Instead, we only request for what we need.

Instead the specs we need should be based on the applicaton’s needs. AWS provides the following predefined profiles to choose from. These profiles are referred to as instance types, here are the main ones:

  • T2 – These are comparitively quite low spec, but they have Burstable Performance Instance, which means that can handle occassional high demands. You have a few T2 specs to choose from:
    • t2.nano
    • t2.micro
    • t2.small
    • t2.medium
    • t2.large
  • M4 –  These are more general purpose VMs. These are EBS storage only, and no SSD.  This means that this is also EBS optimised i.e.  bigger bandwidth
  • M3 – like M4, but with SSD
  • C4 – These vms have emphasis on  cpu power and EBS storage only, and no SSD. This means that this is also EBS optimised i.e. bigger bandwidth
  • C3 – Like C4 but with SSD
  • R3 – these have more emphasis on RAM
  • G2  – these have more emphasis on GPU pcrocessor
  • I2  – these have more emphasis on storage. I.e. large ssd instead of EBS for fast I/0
  • D2 – Like I2 but with even more storage but in HDD form. This is EBS optimised as well.


Elastic Network Interfaces

When you create a new instance, it normally has one default interface, which is eth0, however you can add additional Interfaces, e.g. eth1, et2…etc. There is a limit to how many interfaces you can add, and this limit depends on the instance size. e.g. you can attach more instances on a large instance compared to a nano instance.


Elastic IP address

When you create a new instance, you instance automatically gets to ip addresses:

  • public ip address – this address is not persistant and will change if you shutdown your instance and then start it up again.
  • primary private ip address – this is persistant and used by other resources that are inside your vpc to communicate with each other.

If you want to have a persistent public IP address, then you can achieve this by creating an “Elastic IP Address” and link it up to your private IP address.



Instance Storage

Your EC2 instance’s primary block device can be either one of the following types of block device:

  • Instance Store-backed instances (aka ephemeral storage)
  • EBS (Elastic block store) backed storage

In AWS, the primary block device is referred to as /dev/sda1. In fact /dev/sda doesn’t exist in the world of aws.

The block device type that your instance ends up is dictated by choice of AMI.


Instance Store-backed instances (aka ephemeral storage)

This is temporary storage for the life of the instance. Here are the main features:

  • Data in this  storage gets deleted when the instance is switched-off/shutdown. In fact, the switched-off/shutdown option is actually grayed out, and you can only terminate them.  However the data  does survive a reboot.
  • They are virtual storage that is creating on top of actual SSD devices.
  • These SSD hardware is actually physically attached to the hardware that is hosting your instance. In order to maximise performance.
  • If there are things you want to persist when booting up a power-offed instance, then you should prebake those into the AMI that your instance was built from. Alternatively you can run a bunch of shell scripts after bootup, this kind of “bootstrapping” is possible using a technology called cloud-init.

To create an instance with an ephemeral root device, you nee to choose an ami which is compatible to this setup:

In reality, most of the AMIs in the AMI marketplaces are EBS based. Very few are ephemaral storage based.


EBS (Elastic block store) backed storage

These are network attached storage.

  • You can take snapshots of this and store it in Amazon S3.
  • T2, M4, and C4 uses an EBS for their primary block device. This means you can bootup a powered-off instance without any data loss.
  • If your instance needs to do a lot of reading/writing to the EBS, then this can be a bottleneck. However you can overcome this by one of the following ways:
    • allocating additional IOPS to your instance
    • Create an EBS optimised instance to begin with.
    • ebs sizes can be anywhere between 1gb to 16TB (16000gb)
    • ebs must resided be in the same AZ as the instance that it is connected to.
    • ebs can only be attached to one instance at a time.


EBS-optimized Instances

These are instance that have greater network priority when transferring data to/from EBS.

Instance are EBS-optimised by default for C4, M4, and D2 types. But for the others there is additional fees to enable this feature.

C4, M4, and D2 instances can be shutdown with no loss of data, on it’s primary device, since the device is EBS rather then ephemeral. You can even detach it from one instance and attach it to another, which can be handy for things like realising you needed a C4 instance but currently using and M4 instance.



AMI Images

This is a vm template. This is the amazon’s equivalent to vagrant’s .box file.

All instances are created from an AMI.

You can create your own AMIs using packer.



Security Groups

This is a collection of port numbers you group together and give it a name. e.g. you can create a group called “web-server”. And this group you have whitelisted ports 22, 80, and 443.

You can then assign this to multiple instances. This is a network level security. You still also need to do instance level security, e.g. using RHEL’s firewalld.