DEV Community

Ayo
Ayo

Posted on

Beginner's AWS Guide: Virtual Servers (Part 2)

Objective:

This section explores virtual servers in the cloud, and their role in cloud operations. Here, we dive into managing virtual servers using AWS's primary service, the Elastic Compute Cloud (EC2), along with Elastic Load Balancing (ELB) for distributing traffic and Auto Scaling Groups (ASG) for automatically managing server capacity.


EC2: Elastic Compute Cloud πŸ’»

Amazon EC2 is a service that provides scalable virtual servers (called instances) in the cloud. These virtual servers run on physical hardware in AWS data centres, but we don't need to manage or buy the hardware itself.

Thanks to a software layer called a hypervisor, multiple virtual servers (EC2 instances), including those from different AWS customers, can run safely and independently on the same physical machine!

Simple Analogy:

  • The physical server is like a large apartment building.
  • Each EC2 instance (virtual server) is like a separate apartment unit.
  • The hypervisor is like the building manager who ensures each apartment is isolated, secure, and gets the right utilities (CPU, memory, etc.).

Image highlighting the connection between a physical server, hypervisor, and  virtual server in AWS


EC2: Instance Purchasing Options πŸ’°

When we use EC2, we're renting virtual servers (compute power) from AWS. The base cost comes from AWS managing the physical servers, networking, and infrastructure behind the scenes.

However, on top of this, AWS offers different pricing models to suit varying budgets, workloads, and time commitments.

Here's a quick overview of the most common EC2 pricing models:

Image showing the six most common pricing models for renting virtual servers in AWS


EC2: Instance Set Up πŸ’»πŸ› οΈ

To launch a virtual server (EC2 instance), we must first choose an Amazon Machine Image (AMI), which is basically a pre-configured template that includes:

  • The operating system (e.g., Ubuntu, Amazon Linux, Windows)
  • Pre-installed applications
  • Software configurations

Then, from this, we configure our instance by selecting the following components:

Image highlighting key components of instance configuration: Instance type, storage, networking and security

Image showing a chart of the EC2 instance type options with an accompanying description and mnemonic.

Image showing a chart of the EC2 instance types with an accompanying description and mnemonic.

Simple Analogy: Launching an EC2 Instance is essentially like ordering a custom laptop!

AMI - Choosing our OS and default software
Instance Type - Selecting CPU/RAM (hardware specs)
Storage - Picking SSD/HDD or external drives
Security & Networking - Setting up Wi-Fi, firewall, and login password

πŸ’‘ Golden AMI: Instead of manually configuring an AMI from scratch every time, we can save a customised AMI with all our preferred software and settings, and quickly configure an instance from it.

πŸ’‘ User Data: We can also run custom setup scripts (process called bootstrapping) when our instance first launches, which helps with automation. Common examples include:

  • Installing packages
  • Downloading files
  • Starting apps or services

EC2: Connecting to our Instance πŸ”—

To securely log in to our EC2 instance, we need a key-pair, which is basically a secure digital password. Depending on the operating system and setup, we can connect using:

Image showing table of EC2 Instance connection methods including: SSH, Instance Connect, RDP, and session Manager


ELB: Elastic Load Balancing βš–οΈ

Elastic Load Balancing (ELB) is a fully managed AWS service that automatically distributes incoming traffic across multiple downstream server targets and IP addresses. Under ELB, there are 3 different types of load balancers with unique attributes (ALB, NLB, GLB).

Simple Analogy:

  • Imagine a busy supermarket with multiple checkout tills (servers).
  • Instead of everyone rushing to one till, a smart cashier (the ELB) routes each customer (user request) to the shortest available queue.
  • This keeps things flowing smoothly and prevents an overload on any one till.

Image showing how an ELB directs traffic to multiple downstream instances.

Why Use an ELB?

  1. Single Access Point: Clients connect to one DNS name (provided by the ELB), rather than targeting specific servers.
  2. Traffic Distribution: Spreads traffic evenly across healthy servers, boosting performance.
  3. Fault Tolerance: If one server fails, ELB redirects traffic to healthy ones.
  4. Health Monitoring: ELB runs regular checks to ensure targets are responsive.

Image highlighting the different types of load balancers and their functionality in ELB; ALB, NLB, and GLB

πŸ’‘ We can map DNS names to a custom domain (e.g. myapp.com) using DNS records for user-friendly access.


ASG: Auto Scaling Groups πŸ”ƒ

Auto Scaling Groups (ASG) are another free, managed AWS service that automatically launches or terminates EC2 instances based on real-time demand. This helps us with optimising costs and managing server availability!

How ASG Works:

  • We initially define rules like keep at least 2, but no more than 5 instances running.
  • ASG listens to CloudWatch metrics to make decisions. (Covered further in IAM and Security Fundamentals (Part 6)).
  • Based on demand(s), it automatically scales out (adds instances) or scales in (removes instances).

Essentially, AWS CloudWatch monitors metrics on our instance that we want to track. It then triggers an alarm when thresholds are breached, with ASG responding accordingly. For example, observable metrics could include:

  1. CPU utilisation
  2. Memory usage
  3. Network traffic
  4. Custom metrics (e.g. number of active users)

Image highlighting how auto scaling groups work in AWS

πŸ’‘ ASG relies on a Launch Template that acts like a blueprint, defining exactly what type of EC2 instance to create and how to configure it, including the scaling strategy for when to add or remove instances.

Image highlighting the base requirements for launching new instances in ASG from a launch template

Image highlighting different ASG scaling strategies; manual, dynamic, scheduled, and predictive scaling


🎯 TL;DR

  • EC2 provides virtual servers in the cloud that we can configure and control.
  • Choose instance types based on CPU, memory, and storage needs.
  • ELB spreads traffic across multiple servers for better performance.
  • ASG automatically adds/removes servers based on demand.
  • By combining EC2 + ELB + ASG, we create a resilient, scalable, and cost-efficient setup

✨ This is part of a mini-series where I delve into everything cloud-related. Check out my other posts for further learning! ✨

Top comments (0)