AMAZON EC2Icon-Architecture/64/Arch_Amazon-EC2_64Created with Sketch.

RUNNING VIRTUAL SERVERS IN THE CLOUD

INTRODUCTION👋

Elastic Compute Cloud ≙ (EC2) is one of Amazon's infrastructure as a Service offerings for a broad range of compute requirements, including more than 500 instances with different processors, storage, operating systems and networking capabilities. It's one of the most mature services, released back in 2006!

INSTANCE LIFECYCLE⏱️

Between the launch and the termination of your EC2 instance, there more lifecycle states it transitions through:

  • Launch: creating and launching an instance from an AMI into a VPC, subnet and availability zone. From creating the machine to being available it will be in the pending state.
  • Stop & Start: with EBS volumes you're also able to start and stop your instance. It keeps its instance ID and you won't be billed for the instance while it's stopped, but you'll still pay for the storage of any EBS volume.
  • Hibernate: if supported by the OS, the instance can saved its RAM contents to the EBS root volume. This pre-warmed state takes much quicker to initialize if it's again needed in production and isn't billed.
  • Reboot: restarting your operating system. Your instance will keep private and public IP addresses.
  • Retire: if underlying hardware experiences irreparable failure, AWS will schedule your instance for termination.
  • Terminate: deleting your instance if no longer needed.
  • Recover: instances can automatically recover either on status check or hardware failures.

VIRTUAL MACHINES💻

EC2 instances are virtual machines (VMs) in the cloud. Contrary to physical servers, virtual instances software to create an abstraction from their underlying hardware. This allows securely hosting multiple virtual machines (from different AWS customers) on the same physical hardware.

An instance comes with strong performance and security guarantees, even when the underlying is shared, as AWS dedicates some resources of the host computer such as CPU, memory, and instance storage to the particular instance.

AMAZON MACHINE IMAGES🖼️

AMIs are AWS-maintained configurations that are required to launch an instance. It contains the operating system (e.g. Amazon Linux 2), architecture (32/64-bit ARM or x86-64 install), launch permissions, and storage for the root device.

Developers can also create shared images (Shared AMIs) that are made available for others to use. AWS can't ensure the integrity or security of these AMIs, so it's within your own responsibility.

INSTANCE TYPES

Launching an instance requires you to specify an instance type. This determines the hardware capabilities of the host that is used for your virtual machine.

The instance types are grouped into instance families:

  • General Purpose: balance between compute, memory, and networking resources.
  • Compute Optimized: instances that offer high-performance processors.
  • Memory Optimized: for memory processing of large data sets.
  • Storage Optimized: best fit for workloads requiring high performance reads and writes for locally stored data sets.
  • Accelerated Computing: instances that make use of hardware accelerators and co-processors for fastest processing of specific operations like graphics processing or pattern matching, while also supporting the highest parallelism.

CONNECTING TO YOUR INSTANCE🔌

Key-pairs allow you to securely access your EC2 instances from any location via SSH. If you're launching a new instance, you'll be prompted to either create a new public & private key set or use an existing one. When generating a new pair, AWS will store the public part on the instance (concretely at ~/.ssh/authorized_keys), while asking you to download the private part afterwards. So if you lose it, you can't recover it.

You can also use AWS Systems Manager Session Manager to connect via a browser-based shell or AWS CLI.

As an alternative, you can solely rely on AWS IAM to connect to your instances, not needing to manage any key-pairs. This is achieved with EC2 Instance Connect.

PURCHASES OPTIONS💰

EC2 provides different purchase options with drastically varying in pricing. If you plan to use EC2 regularly, it's a duty to understand the purchase options:

  • On-Demand: the default option, billed by the second after an instance is launched.
  • Reserved / Savings Plan: make a commitment to either an instance configuration (reserved) or usage in USD per hour (savings plan) for a dedicated time frame (1 to 3 years) to significantly lower your bill in comparison to on-demand pricing.
  • Scheduled: reserve capacity based on a schedule for a year. This is currently not available in AWS and nor planned to be reactivated.
  • Spot: use spare EC2 capacity for pricing based on offer & demand, much lower than on-demand. Keep in mind that your workloads can be interrupted if there is not enough spot capacity available.
  • Dedicated Instances & Hosts: launch instances onto physical servers that are isolated at network level. Dedicated instances may share hardware with other instances in the same AWS account, while hosts are not.
  • On-Demand Capacity Reservations: plan EC2 capacity for your machines in a availability zone. Those reservations can be created at any time (no yearly commitments needed) and are independent from the discounts of saving plans or reserved instances.

AWS MARKETPLACE🛒

While many AWS-provided AMIs come with additional software, especially for software development purposes it most likely doesn't include all the software you need.

As described earlier, shared AMIs come to tackle this issue. Additionally, there are shared images that are also paid and therefore increase the price for your instance types. When selecting a paid AMI from AWS Marketplace you'll be informed about the additional usage fees.

STORAGES💾

EC2 comes with a diverse set of possible storage options, each with a unique combination of durability and performance.

Regardless of your requirements, there will be a great fit for you:

  • EC2 Instance Store: providing temporary (ephemeral) storage for your instance, located on disks that are physically attached to the host computer. Use it for cached data, buffers, and temporary content. Data will be lost if the underlying disk fails or the instance stops, hibernates, or terminates.
  • Elastic Block Storage (EBS): block storage volumes that can be mounted to instances. Their persistence is independent from your instance's lifetime. Use it for long-term storage of data that require low latency access, like databases.
  • Elastic File System (EFS): a scalable file storage that can scale based on workload demands. Use it for any workload that can suddenly increase or decrease in storage needs. It can also be used for shared volumes.
  • Simple Storage Service (S3): data storage for unstructured data that are stored with an hierarchy and are only accessed by a unique object identifier.

MONITORING📊

There is a variety of services that helps you to monitor the availability and performance of your instances.

The simplest tools are system status checks and instance status checks. System status are provided and taken care of by AWS and detecting problems with the software or physical hardware, e.g. network connectivity or power loss. Instance status checks are there to detect configuration issues that need to be addressed by yourself, including misconfigured network or exhausted memory.

CloudWatch and EventBridge help you gain more insights into your instances and also react to incidents with automated routines. EC2 automatically sends metrics to CloudWatch, including CPU utilization as well as network and disk usage.

AUTO-SCALING⚖️

You're able to organize your instances into logical groups that can be scaled to scale based on policies, including:

  • Target Tracking: specify target values for a metric, e.g. average CPU or memory consumption.
  • Step Scaling: define one or several thresholds for metrics that will then trigger a scale-in or out event.
  • Scaling based on SQS: if your instances workloads are received on SQS, you can scale based on the queue's depth. This helps you add more workers on a fast-growing queue and remove workers if the queue's state is less busy.
  • Scheduled Scaling: scale based on time and date if you're aware of traffic or workload patterns.