NotesEC2
EC2
Compute building blocks — instance types, EBS vs instance store, purchasing options, AMIs, placement, and operational patterns.
Amazon EC2 Quick Notes
Scaling Vocabulary
- Vertical (scale up/down): Bigger/smaller instance type (e.g.
t2.nano→ metal). Needs reboot; has a size ceiling. - Horizontal (scale out/in): More/fewer instances behind a load balancer.
Storage — EBS vs Instance Store
EBS, Instance store
Attached how: Network volume, Physically on the host
Persistence: Survives stop; detachable, Tied to instance lifecycle
Use when: Persistence / snapshots, Extreme local I/O; app can rebuild
- Bootable:
gp2/gp3,io1/io2(and supported instance store).st1/sc1cannot be boot volumes. - Cost tip:
io1dominating the bill without needing provisioned IOPS → move togp2/gp3. DeleteOnTermination: Root EBS is deleted on terminate by default — set tofalseto keep it.- Encryption: At rest on the volume, on snapshots, and in transit between instance ↔ volume.
- Recycle Bin: Retention rules can recover accidentally deleted EBS snapshots/AMIs.
Purchasing Options
Option: Idea
On-Demand: Pay by the second; no commitment
Reserved / Savings Plans: Commit 1–3 years for discount (steady 24×7)
Spot: Spare capacity; interruptible; deep discount
Spot Fleet: Target capacity across types/AZs
Dedicated Host: Physical host visibility (licensing)
Dedicated Instance: Single-tenant hardware, no host visibility (cheaper single-tenant path)
- Spot trap: Canceling a Spot request does not terminate a running Spot instance.
- Persistent Spot request: Can reopen and replace after interruption.
- Tenancy after launch: Can change
dedicated↔host. Cannot freely flipdefault↔ dedicated/host.
AMI Lifecycle
- Launch → configure → Create Image
- Copy AMI to another Region → creates AMI + snapshot there
- Launch from that AMI → destination has instance + AMI + snapshot
- Sharing: AMIs can be shared across accounts (encrypted AMIs need correct KMS grants).
- Golden AMI: Bake static installs; leave dynamic bits in user data (long Beanstalk bootstraps).
User Data
- Runs only on first launch by default (not every restart).
- Executes as root.
- Cannot update user data on a running instance to re-run it by default.
Hibernation
- Saves RAM to the root EBS volume so stop/start resumes in-memory state.
- Use when bootstrap takes minutes and you need fast wake.
Placement Groups
Type: Fit
Cluster: Low latency / HPC — one AZ
Spread: Separate racks — max ~7 instances per AZ
Partition: Large distributed ETL / Hadoop-style isolation
- EFA (Elastic Fabric Adapter): OS-bypass HPC networking for tightly coupled MPI workloads.
Instance Access & Ops
- Instance profile / role: Prefer over access keys on disk.
- EC2 Instance Connect: Inject a temporary SSH public key.
- CloudWatch recover: System-status failure → recover keeps instance ID / private IPs / EIPs (auto public IPv4 may change).
- Detailed monitoring: 1-minute metrics (vs basic 5-minute).
- AZ IDs:
us-west-2ais randomized per account — use AZ ID to align physical AZs across accounts.