Chapter 5: Amazon EC2 (Elastic Compute Cloud)
5.2 What is EC2? Key concepts
Think of EC2 like renting a fully furnished flat instead of building a house: you choose the size (instance type), the interior setup (AMI), the lock and key (key pair) and the society gate rules (security group). Technically, EC2 runs your virtual machine on AWS's Nitro hypervisor in a data centre of the region you choose. Bagha the key terms:
Amazon EC2 provides resizable virtual servers called instances in the AWS cloud.
AWS Region: Asia Pacific (Mumbai) ap-south-1
+---------------------------------------------------------------------+
| Availability Zone ap-south-1a Availability Zone ap-south-1b |
| +---------------------------+ +---------------------------+ |
| | VPC subnet | | VPC subnet | |
| | +---------------------+ | | +---------------------+ | |
| | | EC2 instance | | | | EC2 instance | | |
| | | AMI: Ubuntu 24.04 | | | | AMI: AL2023 | | |
| | | Type: t3.micro | | | | Type: t3.small | | |
| | | SG: web-sg | | | | SG: web-sg | | |
| | +----------+----------+ | | +----------+----------+ | |
| | | EBS vol | | | EBS vol | |
| +---------------------------+ +---------------------------+ |
+---------------------------------------------------------------------+
| Term | What it is | Example / notes |
|---|---|---|
| Instance | A virtual server | i-0abc123def4567890 |
| AMI (Amazon Machine Image) | Template with OS + software used to launch instances | Amazon Linux 2023, Ubuntu 24.04, CentOS Stream 9, your own custom AMI |
| Instance type | Hardware size: vCPU, RAM, network | t3.micro (2 vCPU, 1 GiB), t3.medium (2 vCPU, 4 GiB) |
| Key pair | Public/private key used for SSH login instead of a password | AWS keeps public key; you download mykey.pem once |
| Security group (SG) | Stateful virtual firewall at instance level | Allow TCP 22 from My IP, TCP 80/443 from 0.0.0.0/0 |
| EBS volume | Network-attached block storage (virtual hard disk) | Root volume 8 GiB gp3 |
| Instance store | Temporary disk physically attached to host | Data lost on stop/terminate (only on some types) |
| Elastic IP | Static public IPv4 address | Survives stop/start; re-mappable |
| Region | Geographic area with multiple data centres | ap-south-1 Mumbai, us-east-1 N. Virginia |
| Availability Zone (AZ) | One or more isolated data centres inside a region | ap-south-1a, ap-south-1b, ap-south-1c |
| VPC / subnet | Your private network / a slice of it in one AZ | Default VPC 172.31.0.0/16 |
| User data | Script that runs automatically at first boot | Install Nginx on launch |
| IAM role (instance profile) | Gives the instance AWS permissions without storing access keys | Allow instance to read from S3 |
Instance type naming
t 3 a . micro
│ │ │ └── size: nano, micro, small, medium, large, xlarge, 2xlarge ...
│ │ └──────── extra attribute: a = AMD, g = Graviton (ARM), i = Intel, d = local NVMe, n = network
│ └─────────── generation (higher = newer, better price/performance)
└────────────── family: t = burstable general purpose
| Family | Category | Use case | Examples |
|---|---|---|---|
| T | General purpose, burstable (CPU credits) | Dev/test, small websites, labs | t3.micro, t3.small, t4g.small |
| M | General purpose, balanced | App servers, small databases | m7i.large, m7g.large |
| C | Compute optimised | Batch processing, gaming, high-traffic web | c7i.xlarge |
| R / X | Memory optimised | Large databases, in-memory caches | r7i.large |
| I / D | Storage optimised | NoSQL, data warehouses | i4i.large |
| P / G / Inf / Trn | Accelerated (GPU/ML chips) | Machine learning, video | g5.xlarge |
Graviton (ARM) instances
Types with g (e.g. t4g, m7g) use AWS Graviton ARM processors — usually cheaper for the same performance. Choose an arm64 AMI for them. All software in this book works on both x86_64 and arm64.
Pricing models
| Model | How it works | Discount vs On-Demand | Best for |
|---|---|---|---|
| On-Demand | Pay per second (Linux, min 60 s); no commitment | — | Labs, unpredictable workloads |
| Savings Plans | Commit to a $/hour spend for 1 or 3 years | Up to ~72% | Steady long-term usage |
| Reserved Instances | Commit to a specific instance type/region for 1 or 3 years | Up to ~72% | Always-on production servers |
| Spot Instances | Use spare capacity; AWS can reclaim with 2-minute notice | Up to ~90% | Fault-tolerant batch jobs, CI, rendering |
| Dedicated Hosts / Instances | Physical server dedicated to you | Premium | Licensing, compliance |
What you pay for: instance running time, EBS storage (even when the instance is stopped), snapshots, public IPv4 addresses (including Elastic IPs), and data transfer out to the internet.
Free tier
AWS offers a free tier / free plan for new accounts (typically covering small instance types such as t2.micro/t3.micro, some EBS storage and limited data transfer, or credits for new accounts). The exact offer depends on when your account was created and changes over time — always check aws.amazon.com/free and look for the "Free tier eligible" label in the console. Set up an AWS Budget with e-mail alerts before starting labs.
Ravindra Bagale's Tip
The very first thing to do in a new AWS account is not launching an instance — it is creating an AWS Budget with an email alert (even a small amount like ₹500 equivalent) and enabling MFA on the root user. Then create an IAM user for daily work. Security and cost control first, experiments later.