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.).
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:
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 showing a chart of the EC2 instance type options 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:
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.
Why Use an ELB?
- Single Access Point: Clients connect to one DNS name (provided by the ELB), rather than targeting specific servers.
- Traffic Distribution: Spreads traffic evenly across healthy servers, boosting performance.
- Fault Tolerance: If one server fails, ELB redirects traffic to healthy ones.
- Health Monitoring: ELB runs regular checks to ensure targets are responsive.
π‘ 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:
CPU utilisation
Memory usage
Network traffic
Custom metrics (e.g. number of active users)
π‘ 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.
π― 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)