Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 5: Amazon EC2 (Elastic Compute Cloud)

5.2 What is EC2? Key concepts

Think of EC2 as renting a furnished flat – you don't have to build the house yourself. You choose the size of the flat (instance type), the setup inside (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. Because of the hypervisor (the software that runs many virtual machines on one physical server), the servers of many customers run separately on one big machine. Come on, now look at 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 (e.g. a Nashik grape exporter's app reading its invoices bucket)

In Mauli Dairy's terms: their website will run on one instance. For the OS the AMI is Amazon Linux 2023, for the size t3.micro, for login the key pair mauli-key.pem, and the security group has only three doors – 22 (only My IP), 80 and 443. The customers are in Maharashtra, so the nearest region is Mumbai (ap-south-1). A security group is stateful (it automatically lets the reply to an allowed incoming request go back out) – so you don't need a separate outbound rule for the reply to an allowed request.

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

Burstable (able to use more CPU for a short time when needed) means the T family: low CPU at normal times, and when a rush comes it uses CPU credits to run faster for a while. For a small website like Mauli Dairy's and for our labs, the T family is just right.

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

Friends, the first job in a new AWS account is not launching an instance – first create an AWS Budget with an e-mail alert (even a small amount like ₹500 equivalent will do) and turn on MFA for the root user. Then create an IAM user for daily work. Security and cost control first, experiments later.

Ravindra Bagale's Tip

In interviews many students mix up Region and AZ. Remember: a Region is an area (Mumbai ap-south-1), and an AZ is one or more isolated data centres inside that region (ap-south-1a). An instance always runs in one AZ, and the console shows you only the resources of the selected region.

Practice task

Mauli Dairy sathi ek launch checklist lihun kadha: Region, AZ, AMI, instance type, key pair che naav, security group rules aani root volume size. Pratyek line samor ek chhota karan liha – udaharan mhanje "Mumbai, karan customers Maharashtra madhe aahet".

Quick revision cards

Revise this lesson in two minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens its lesson.

Comparison card: On-Demand vs Savings Plans / Spot. On-Demand: Pay per second or hour, no commitment. Savings Plans / Spot: Savings Plans: commit for 1 or 3 years. Spot: use spare AWS capacity.
Comparison: On-Demand vs Savings Plans / Spot · Download PNG

More cards: Ravi Sir's Cards.