Skip to content

You are viewing a free preview of this lesson.

Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.

Introduction to Amazon EC2

Introduction to Amazon EC2

Amazon Elastic Compute Cloud (EC2) is the backbone of AWS compute. It lets you launch virtual servers — called instances — in minutes, scale capacity up or down on demand, and pay only for what you use. Whether you need a single development box or thousands of production servers, EC2 provides the building blocks.


What Is Amazon EC2?

EC2 is an Infrastructure as a Service (IaaS) offering. You get full control over the operating system, networking, and storage of every instance you launch. AWS manages the physical hardware, hypervisor, and data-centre facilities; you manage everything from the guest OS upward.

Think of EC2 as renting a computer in the cloud. You choose:

  • The size (CPU, RAM, network bandwidth)
  • The operating system (Amazon Linux, Ubuntu, Windows Server, Red Hat, etc.)
  • The storage (local disks, network-attached volumes)
  • The network configuration (VPC, subnet, security group, public/private IP)

Once the instance is running, you can SSH or RDP into it just like a physical machine.


Why EC2 Matters

Before EC2, provisioning a new server could take weeks — procurement, racking, cabling, OS installation, and configuration. EC2 reduces that to minutes or seconds. This speed unlocks several benefits:

Benefit Description
Elasticity Scale from one instance to thousands, then back down
Cost efficiency Pay per second (Linux) or per hour (Windows), with no long-term commitment required
Global reach Launch instances in any AWS Region or Availability Zone
Variety 750+ instance types optimised for different workloads
Integration Tight integration with other AWS services (S3, RDS, IAM, CloudWatch, etc.)
Reliability Built on AWS's proven global infrastructure with multiple levels of redundancy

Core Concepts

Instances

An EC2 instance is a virtual server. Each instance runs on a physical host managed by AWS and is isolated from other instances using the Nitro Hypervisor (or the older Xen hypervisor for legacy instance types).

Amazon Machine Images (AMIs)

An AMI is a template that contains the operating system, application server, and applications. You select an AMI when you launch an instance. AWS provides thousands of public AMIs, and you can create your own custom AMIs.

Instance Types

Instance types determine the hardware profile — how many vCPUs, how much RAM, what storage is available, and how much network bandwidth the instance receives. Instance types are grouped into families (e.g., General Purpose, Compute Optimised, Memory Optimised).

Regions and Availability Zones

AWS operates in multiple Regions around the world (e.g., us-east-1, eu-west-2). Each Region contains multiple Availability Zones (AZs) — physically separate data centres with independent power, cooling, and networking. Spreading instances across AZs improves fault tolerance.

Key Pairs

AWS uses public-key cryptography to secure login to instances. You create a key pair; AWS stores the public key on the instance, and you keep the private key. For Linux instances, you use the private key with SSH; for Windows, you decrypt the administrator password.

Security Groups

A security group acts as a virtual firewall controlling inbound and outbound traffic to your instance. By default, all inbound traffic is denied and all outbound traffic is allowed. You add rules to permit specific protocols, ports, and source IP ranges.


Launching Your First Instance

The simplest way to launch an instance is through the AWS Management Console:

  1. Open the EC2 Dashboard and click Launch Instance.
  2. Name your instance (e.g., "my-first-server").
  3. Choose an AMI — start with Amazon Linux 2023 (free-tier eligible).
  4. Select an instance typet2.micro is free-tier eligible (1 vCPU, 1 GiB RAM).
  5. Create or select a key pair for SSH access.
  6. Configure network settings — accept defaults or choose your VPC and subnet.
  7. Configure storage — the default 8 GiB gp3 EBS volume is a good starting point.
  8. Review and launch.

After a few seconds the instance enters the running state and you receive a public IP address (if enabled).

Connecting via SSH

# Make your private key read-only
chmod 400 my-key-pair.pem

# Connect to the instance
ssh -i my-key-pair.pem ec2-user@<public-ip>

Replace ec2-user with the appropriate default user for your AMI (ubuntu for Ubuntu, Administrator for Windows via RDP).


EC2 Instance Lifecycle

Every EC2 instance moves through a series of states:

pending → running → stopping → stopped → terminated
                  ↘ shutting-down → terminated
                  ↗ rebooting → running
State Description Billing?
pending Instance is being prepared No
running Instance is active and reachable Yes
stopping Instance is in the process of stopping Depends on instance store
stopped Instance is shut down; EBS volumes persist No (but EBS charges apply)
shutting-down Instance is being terminated No
terminated Instance is deleted; cannot be restarted No
rebooting Instance is rebooting; stays in "running" Yes

Key points:

  • Stopping an instance preserves its EBS root volume and any attached EBS volumes. You can restart it later without losing data.
  • Terminating an instance permanently deletes it. The default behaviour deletes the root EBS volume, but you can change this with the DeleteOnTermination attribute.
  • You are not charged for a stopped instance (but EBS storage charges continue).
  • Instance store data is lost whenever an instance stops or terminates.

The AWS CLI

While the console is great for exploration, most production workflows use the AWS CLI or SDKs. Here are common EC2 commands:

# List running instances
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running"

# Launch an instance
aws ec2 run-instances \
  --image-id ami-0abcdef1234567890 \
  --instance-type t3.micro \
  --key-name my-key-pair \
  --security-group-ids sg-0123456789abcdef0 \
  --subnet-id subnet-0bb1c79de3EXAMPLE

# Stop an instance
aws ec2 stop-instances --instance-ids i-0123456789abcdef0

# Terminate an instance
aws ec2 terminate-instances --instance-ids i-0123456789abcdef0

EC2 and the Shared Responsibility Model

Understanding what you manage versus what AWS manages is critical:

Your Responsibility AWS Responsibility
Guest OS patches and updates Physical host hardware
Application software Hypervisor and firmware
Security group rules Data-centre security
Data encryption Network infrastructure
IAM policies and access control Power, cooling, environmental controls

Summary

Amazon EC2 is the foundation of compute on AWS. It provides virtual servers with full OS-level control, a rich set of instance types, and seamless integration with the broader AWS ecosystem. Understanding how to launch, connect to, manage, and terminate instances — along with the shared responsibility model — is the first step toward building scalable, reliable infrastructure in the cloud.