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:
EC2 ला एक फर्निश्ड फ्लॅट भाड्याने घेण्यासारखं समजा – घर स्वतः बांधायचं नाही. फ्लॅटचा साइझ (इन्स्टन्स टाइप), आतला सेटअप (AMI), कुलूप आणि चावी (की पेअर) आणि सोसायटी गेटचे नियम (सिक्युरिटी ग्रुप) हे तुम्ही निवडता. टेक्निकली, EC2 तुमची व्हर्च्युअल मशीन तुम्ही निवडलेल्या रिजनमधल्या डेटा सेंटरमध्ये AWS च्या Nitro हायपरव्हायझरवर चालवतो. हायपरव्हायझरमुळे (एका फिजिकल सर्व्हरवर अनेक व्हर्च्युअल मशीन्स चालवणारा सॉफ्टवेअर) एकाच मोठ्या मशीनवर अनेक कस्टमर्सचे सर्व्हर्स वेगवेगळे चालतात. चला, आता की टर्म्स बघा:
EC2 को एक फ़र्निश्ड फ़्लैट किराए पर लेने जैसा समझो – घर खुद नहीं बनाना पड़ता. फ़्लैट का साइज़ (इंस्टेंस टाइप), अंदर का सेटअप (AMI), ताला और चाबी (की पेयर) और सोसाइटी गेट के नियम (सिक्योरिटी ग्रुप) आप चुनते हो. टेक्निकली, EC2 आपकी वर्चुअल मशीन को आपके चुने हुए रीजन के डेटा सेंटर में AWS के Nitro हाइपरवाइज़र पर चलाता है. हाइपरवाइज़र (एक फ़िज़िकल सर्वर पर कई वर्चुअल मशीनें चलाने वाला सॉफ़्टवेयर) की वजह से एक ही बड़ी मशीन पर कई कस्टमर्स के सर्वर अलग-अलग चलते हैं. चलो, अब की टर्म्स देखो:
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.
Mauli Dairy च्या भाषेत सांगायचं तर: त्यांची वेबसाइट एका इन्स्टन्सवर चालणार. OS साठी AMI Amazon Linux 2023, साइझसाठी t3.micro, लॉगिनसाठी mauli-key.pem हा की पेअर, आणि सिक्युरिटी ग्रुपमध्ये फक्त तीन दरवाजे – 22 (फक्त My IP), 80 आणि 443. कस्टमर्स महाराष्ट्रात आहेत म्हणून जवळचा रिजन Mumbai (ap-south-1). सिक्युरिटी ग्रुप stateful (आत आलेल्या रिक्वेस्टचं उत्तर आपोआप बाहेर जाऊ देणारा) आहे – म्हणजे अलाउ केलेल्या रिक्वेस्टचा रिप्लाय परत जाण्यासाठी वेगळा outbound रूल लागत नाही.
Mauli Dairy की भाषा में कहें तो: उनकी वेबसाइट एक इंस्टेंस पर चलेगी. OS के लिए AMI Amazon Linux 2023, साइज़ के लिए t3.micro, लॉगिन के लिए mauli-key.pem वाला की पेयर, और सिक्योरिटी ग्रुप में सिर्फ़ तीन दरवाज़े – 22 (सिर्फ़ My IP), 80 और 443. कस्टमर्स महाराष्ट्र में हैं, इसलिए सबसे पास का रीजन Mumbai (ap-south-1). सिक्योरिटी ग्रुप stateful (अंदर आई रिक्वेस्ट का जवाब अपने आप बाहर जाने देने वाला) होता है – यानी अलाउ की गई रिक्वेस्ट का रिप्लाय वापस भेजने के लिए अलग outbound रूल नहीं चाहिए.
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.
Burstable (गरज पडल्यावर थोड्या वेळासाठी जास्त CPU वापरू शकणारा) म्हणजे T फॅमिली: नॉर्मल वेळी कमी CPU, आणि गर्दी आली की CPU क्रेडिट्स वापरून थोडा वेळ जास्त CPU. Mauli Dairy सारख्या छोट्या वेबसाइटसाठी आणि आपल्या लॅब्ससाठी T फॅमिली एकदम बरोबर आहे.
Burstable (ज़रूरत पड़ने पर थोड़ी देर के लिए ज़्यादा CPU इस्तेमाल कर सकने वाला) मतलब T फ़ैमिली: नॉर्मल समय में कम CPU, और भीड़ आने पर CPU क्रेडिट्स इस्तेमाल करके थोड़ी देर ज़्यादा CPU. Mauli Dairy जैसी छोटी वेबसाइट के लिए और हमारी लैब्स के लिए T फ़ैमिली बिल्कुल सही है.
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 – मराठी
मित्रांनो, नवीन AWS account मध्ये पहिलं काम instance launch करणं नाही – आधी e-mail alert सोबत एक AWS Budget बनवा (₹500 equivalent सारखी छोटी amount सुद्धा चालेल) आणि root user वर MFA चालू करा. मग रोजच्या कामासाठी एक IAM user बनवा. आधी security आणि खर्चावर control, experiments नंतर.
Ravindra Bagale's Tip – हिंदी
दोस्तों, नए AWS account में पहला काम instance launch करना नहीं है – पहले e-mail alert के साथ एक AWS Budget बनाओ (₹500 equivalent जैसी छोटी amount भी चलेगी) और root user पर MFA चालू करो. फिर रोज़ के काम के लिए एक IAM user बनाओ. पहले security और खर्च पर control, experiments बाद में.
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.
Ravindra Bagale's Tip – मराठी
Interview मध्ये बरेच students Region आणि AZ उलटं सांगतात. लक्षात ठेवा: Region म्हणजे area (Mumbai ap-south-1), आणि AZ म्हणजे त्या region मधलं एक किंवा जास्त isolated data centres (ap-south-1a). Instance नेहमी एका AZ मध्ये चालतो, आणि console तुम्हाला फक्त select केलेल्या region चे resources दाखवतो.
Ravindra Bagale's Tip – हिंदी
Interview में बहुत से students Region और AZ उल्टा बताते हैं. याद रखो: Region मतलब area (Mumbai ap-south-1), और AZ मतलब उस region के अंदर एक या ज़्यादा isolated data centres (ap-south-1a). Instance हमेशा एक AZ में चलता है, और console आपको सिर्फ़ select किए गए region के resources दिखाता है.
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.

More cards: Ravi Sir's Cards.