☁️ AWS EC2 Mastery Guide

Core arguments · Actionable methods · Valuable quotes · Concept explanations

🧠

Core Arguments

17 Points

1. Sizing is multidimensional

EC2 sizing involves OS, CPU, RAM, storage (EBS/EFS/instance store), network card, firewall rules, and bootstrap scripts — not just instance type.

2. User Data runs once

User Data scripts execute only at first boot with root privileges, automating software installation, updates, and configuration.

3. Instance type naming matters

The convention m5.2xlarge encodes family (m), generation (5), and size (2xlarge) — critical for right-sizing.

4. Security groups are stateful

They contain allow rules only, evaluate all rules before deciding, and are attached at the network interface level. Default: deny inbound, allow outbound.

5. Purchasing is a cost-commitment tradeoff

On-Demand (no commitment), Reserved/Savings Plans (1–3 years, up to 72% off), Spot (up to 90% off, interruptible), Dedicated Host (BYOL).

6. Placement groups control physical layout

Cluster (low latency), Spread (fault tolerance), Partition (large distributed workloads) — each optimizes for a different tradeoff.

7. EBS is persistent, instance store is ephemeral

EBS volumes persist independently of instance lifecycle; instance store data is lost when the instance stops or terminates.

8. Snapshots are incremental backups

EBS snapshots only store changed blocks after the first full snapshot, stored in S3 and used to restore volumes.

9. AMI vs. Snapshot: different scopes

AMIs are templates to launch new instances (include launch permissions, block device mapping); snapshots back up individual volumes.

10. Archive cuts costs by 75%

EBS Snapshot Archive is for rarely accessed snapshots stored 90+ days; retrieval takes 24–72 hours.

11. Recycle Bin is a safety net

Retention rules preserve deleted EBS volumes, snapshots, and AMIs for 1–365 days, preventing accidental data loss.

12. FSR eliminates first-access latency

Fast Snapshot Restore creates fully initialized volumes from snapshots, removing I/O latency on first block access — billed per minute per AZ.

13. Volume types map to workloads

SSD (gp2/gp3/io1/io2) for transactional/random I/O; HDD (st1/sc1) for throughput-intensive or cold data.

14. Encryption is host-level, not volume-level

EBS encryption uses AES-256 and AWS KMS; data is encrypted at rest and in transit between EC2 and EBS.

15. Instance store is high-performance but temporary

Physically attached storage offers lower latency and higher IOPS than EBS, but data does not survive instance stop/termination.

16. EFS is serverless and elastic

Amazon EFS automatically scales to petabytes, supports NFS for Linux, and offers General Purpose (low latency) and Max I/O performance modes.

17. Default security group behavior is permissive outbound

New security groups allow all outbound traffic and deny all inbound; you must explicitly add inbound rules to enable access.

⚙️

Applicable Methods

8 Steps
1

Launch an EC2 instance with User Data

Pass a bootstrap script via --user-data to automate first-boot configuration. The script runs as root and executes only once.

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t3.micro \ --security-group-ids sg-0123456789abcdef0 \ --user-data file://bootstrap.sh \ --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=WebServer}]'
2

Create a Security Group with specific inbound rules

Security groups are stateful; add only the inbound rules you need. Outbound is allowed by default.

aws ec2 create-security-group \ --group-name WebServerSG \ --description "Allow HTTP and SSH" \ --vpc-id vpc-0abc123def4567890 aws ec2 authorize-security-group-ingress \ --group-id sg-0123456789abcdef0 \ --protocol tcp \ --port 80 \ --cidr 0.0.0.0/0
3

Attach an EBS volume to a running instance

Create a volume in the same AZ, then attach it. EBS volumes persist independently of the instance.

aws ec2 create-volume \ --availability-zone us-east-1a \ --size 100 \ --volume-type gp3 aws ec2 attach-volume \ --volume-id vol-0abcdef1234567890 \ --instance-id i-0abcdef1234567890 \ --device /dev/sdf
4

Create an EBS snapshot

Snapshots are incremental backups stored in S3. The first snapshot is full; subsequent snapshots only store changed blocks.

aws ec2 create-snapshot \ --volume-id vol-0abcdef1234567890 \ --description "Daily backup of web data" \ --tag-specifications 'ResourceType=snapshot,Tags=[{Key=Name,Value=WebDataBackup}]'
5

Enable Fast Snapshot Restore (FSR)

FSR creates fully initialized volumes instantly. Enable it per snapshot per Availability Zone (up to 5 per Region).

aws ec2 enable-fast-snapshot-restores \ --availability-zones us-east-1a \ --source-snapshot-ids snap-0abcdef1234567890
6

Archive an EBS snapshot for long-term retention

Move rarely accessed snapshots to the Archive tier (90+ days) to reduce storage costs by up to 75%. Retrieval takes 24–72 hours.

aws ec2 create-snapshot ... # create snapshot first aws ec2 modify-snapshot-tier \ --snapshot-id snap-0abcdef1234567890 \ --storage-tier archive
7

Create a Recycle Bin retention rule

Protect against accidental deletion by retaining EBS snapshots and AMIs for 1–365 days.

aws rbin create-rule \ --resource-type EBS_SNAPSHOT \ --retention-period 'RetentionPeriodValue=30,RetentionPeriodUnit=DAYS' \ --description "Retain deleted snapshots for 30 days"
8

Mount an Amazon EFS file system on EC2

EFS provides shared, elastic NFS storage for Linux instances. Install the EFS mount helper and mount at boot.

# On the EC2 instance sudo yum install -y amazon-efs-utils sudo mount -t efs -o tls,iam fs-0123456789abcdef0:/ /mnt/efs # Persist in /etc/fstab fs-0123456789abcdef0:/ /mnt/efs efs _netdev,tls,iam 0 0
💬

Valuable Quotes

16 Quotes

"Security groups act as stateful virtual firewalls attached to EC2 instances at the network interface level."

— AWS Documentation

"User data is a powerful feature for automating the setup of EC2 instances. It runs only once at the instance's first start."

— AWS Documentation

"EBS snapshots are incremental backups, which means that only the blocks on the device that have changed after your most recent snapshot are saved."

— AWS Documentation

"Fast snapshot restore enables you to create a volume from a snapshot that is fully initialized at creation, eliminating I/O latency on first access."

— AWS Documentation

"Amazon EBS Snapshots Archive offers storage costs up to 75% lower for snapshots you plan to store for 90 days or more and rarely need to access."

— AWS Documentation

"Recycle Bin is a data recovery feature that enables you to restore accidentally deleted Amazon EBS snapshots and EBS-backed AMIs."

— AWS Documentation

"The cost of an instance AMI is the storage of all the volumes on the instance, but not the metadata. The cost for an EBS snapshot is the storage of the individual volume."

— AWS Documentation

"Instance store provides temporary block-level storage for your instance. This storage is located on disks that are physically attached to the host computer."

— AWS Documentation

"Amazon EFS provides simple, scalable file storage for use with Amazon EC2 Linux and Mac instances in the AWS Cloud."

— AWS Documentation

"Placement groups allow you to influence the placement of a group of interdependent instances to meet the needs of your workload."

— AWS Documentation

"EBS encryption uses AWS KMS keys to encrypt data at rest inside the volume, data in transit between the volume and the instance, and snapshots."

— AWS Documentation

"General Purpose SSD volumes balance price and performance for a wide variety of transactional workloads."

— AWS Documentation

"Provisioned IOPS SSD volumes are designed for latency-sensitive transactional workloads such as databases."

— AWS Documentation

"Throughput Optimized HDD volumes are ideal for frequently accessed, throughput-intensive workloads such as big data and data warehouses."

— AWS Documentation

"Cold HDD volumes provide low-cost storage for infrequently accessed data where performance is not critical."

— AWS Documentation

"By default, new security groups start with only an outbound rule that allows all traffic to leave the resource. You must add rules to enable any inbound traffic."

— AWS Documentation
📚

Concept Explanations

16 Concepts
🖥️ Compute

EC2 (Elastic Compute Cloud)

Rentable virtual servers in the cloud. You choose OS, CPU, RAM, storage, and networking.

🏠 Like renting an apartment — you pick the size, location, and lease terms, but you don't own the building.

💾 Storage

EBS (Elastic Block Store)

Persistent block-level storage volumes for EC2. Survives instance stop/termination independently.

🔌 Like an external hard drive — you can detach it from one computer and attach it to another.

🛡️ Networking

Security Group

Stateful virtual firewall at the instance level. Allow rules only; default deny inbound, allow outbound.

🚪 Like a bouncer at a club — only lets in people on the guest list (allow rules) and remembers who they are.

📐 Networking

Placement Group

Controls physical placement of instances: Cluster (low latency), Spread (fault tolerance), Partition (large workloads).

🪑 Like seating arrangements at a wedding — some want to sit together (cluster), some apart (spread).

📜 Automation

User Data

Bootstrap script that runs once at first boot with root privileges. Automates software installs and configuration.

📋 Like a checklist you give a new employee on their first day — they follow it once to get set up.

Storage

Instance Store

Temporary, physically attached storage with high IOPS and low latency. Data lost on stop/termination.

🧠 Like short-term memory — fast and useful now, but gone when you power off.

📂 Storage

Amazon EFS

Serverless, elastic NFS file system for Linux. Scales automatically to petabytes.

📁 Like a shared Google Drive for your EC2 instances — everyone can access the same files.

📦 Management

AMI (Amazon Machine Image)

Template for launching instances. Includes OS, application server, applications, and launch permissions.

🍪 Like a cookie cutter — use it to stamp out identical instances with the same pre-baked configuration.

📸 Backup

EBS Snapshot

Incremental backup of an EBS volume stored in S3. Used to restore volumes or create new ones.

📷 Like a photo backup — each new photo only saves what changed from the last one.

🚀 Performance

Fast Snapshot Restore

Creates fully initialized volumes from snapshots instantly, eliminating first-access I/O latency.

⚡ Like pre-heating an oven — no waiting for it to warm up when you need to bake.

🗄️ Cost Optimization

EBS Snapshot Archive

Low-cost storage tier for snapshots kept 90+ days. Up to 75% cheaper; retrieval takes 24–72 hours.

🏚️ Like storing old tax returns in a basement — cheap, but takes time to retrieve when needed.

♻️ Data Protection

Recycle Bin

Retention rules that preserve deleted EBS volumes, snapshots, and AMIs for 1–365 days.

🗑️ Like your computer's Recycle Bin — deleted files stay recoverable for a set period.

🔢 Storage

EBS Volume Types

SSD (gp2/gp3/io1/io2) for transactional; HDD (st1/sc1) for throughput or cold data.

🚗 Like choosing between a sports car (SSD) and a truck (HDD) — each excels at different jobs.

🔐 Security

EBS Encryption

AES-256 encryption at the EC2 host level using AWS KMS. Encrypts data at rest and in transit.

🔒 Like a safe that automatically locks itself — you don't manage the lock, it just works.

💰 Cost Management

Purchasing Options

On-Demand, Reserved, Savings Plans, Spot, Dedicated Host/Instance, Capacity Reservation.

🎟️ Like buying tickets — pay full price anytime (On-Demand), or commit early for a discount (Reserved).

🧩 Compute

Instance Type

Family + generation + size. Families: General Purpose (T/M), Compute (C), Memory (R/X), Storage (I/D).

👕 Like clothing sizes — you pick the fit that matches your workload's needs.