SkillSprout
Chapter 11 · Lesson 1
Advanced
7 min read

Troubleshooting EC2 Instances

Overview

When an EC2 instance misbehaves, a methodical approach beats guessing. Start with what AWS tells you (status checks, events, console output and screenshot), then check permissions and network, then look inside the OS. Most cases fall into a handful of patterns that repeat in real life and on the exam.

Think of a car that won't start. First check the dashboard warning lights (status checks), then whether there is fuel (capacity, quotas, EBS), then whether the key works (key pairs, IAM), and only then open the bonnet (logs, Rescue). Jumping straight to the engine wastes time.

This lesson is organised as symptom -> likely causes -> verification command -> fix, mirroring the runbooks you will write at work.

Key Concepts

  • System status check failures are AWS-side (host, power, network) -> stop/start (new host) or recover alarm; instance status check failures are in-guest (OS, network config, file system) -> reboot / fix OS.
  • Launch errors: InstanceLimitExceeded (vCPU quota), InsufficientInstanceCapacity (try another AZ/type, or wait), Client.InternalError / KMS issues for encrypted volumes, VolumeLimitExceeded.
  • SSH/RDP failures: security group, NACL, route/IGW, public IP, key pair mismatch, wrong user, permissions on .pem (chmod 400), full disk or sshd down.
  • Use Get console output, instance screenshot, EC2 Serial Console, EC2Rescue / AWSSupport-ExecuteEC2Rescue to fix unreachable instances.
  • Burstable (T-series) instances throttle when CPUCreditBalance hits zero; switch to Unlimited, larger size or non-burstable family.
  • Stuck in stopping: wait, then force stop; stuck in pending/terminating are usually AWS-side; open support case if persistent.
  • Changing instance type needs stop/start; the instance ID persists but public IP changes unless Elastic IP; instance store data is lost.
  • IMDSv2 (token-based) protects credentials; apps using IMDSv1 break if it is required.

Detailed Notes

Status checks

CheckFailure indicatesTypical action
System status (StatusCheckFailed_System)Loss of network connectivity/power, hardware or hypervisor issueStop and start (migrates host), or alarm with recover
Instance status (StatusCheckFailed_Instance)Corrupt file system, wrong /etc/fstab, kernel panic, exhausted memory, misconfigured networkingReboot; fix through console output, Rescue
Attached EBS statusVolume impairedCheck volume status, restore from snapshot
bash
aws ec2 describe-instance-status --instance-ids i-0abc --include-all-instances
aws ec2 get-console-output --instance-id i-0abc --latest --output text
aws ec2 get-console-screenshot --instance-id i-0abc
aws ec2 describe-instance-attribute --instance-id i-0abc --attribute userData

Cannot connect via SSH

CheckCommand / location
Instance running with 2/2 checksConsole / describe-instance-status
Public IP or EIPdescribe-instances --query "Reservations[].Instances[].PublicIpAddress"
Route to IGWRoute table of the subnet
SG inbound 22 from your IPdescribe-security-groups
NACL inbound 22 and outbound ephemeraldescribe-network-acls
Key pair and userec2-user, ubuntu, admin; correct .pem; chmod 400
Full disk / sshdUse Session Manager or Serial Console

If SSM is working, skip SSH entirely: aws ssm start-session --target i-0abc.

Repair an unreachable instance

bash
# Automated repair
aws ssm start-automation-execution --document-name AWSSupport-ExecuteEC2Rescue \
  --parameters UnreachableInstanceId=i-0abc,AutomationAssumeRole=arn:aws:iam::111122223333:role/AutoRole

# Manual method: stop, detach root volume, attach to rescue instance, fix, reattach as /dev/xvda
aws ec2 stop-instances --instance-ids i-0abc
aws ec2 detach-volume --volume-id vol-0root
aws ec2 attach-volume --volume-id vol-0root --instance-id i-0rescue --device /dev/sdf

Typical fixes: correct /etc/fstab errors (use nofail), reset a lost key by adding a new public key to authorized_keys on the mounted volume (or use EC2 Instance Connect / Session Manager), clear a full root volume.

Launch failures

ErrorResolution
InstanceLimitExceededRequest Service Quotas increase for the instance family's vCPUs
InsufficientInstanceCapacityRetry later, use another AZ/instance type, use ASG with multiple types, On-Demand Capacity Reservation
InvalidAMIID.NotFoundWrong Region or AMI not shared/deregistered
Client.InvalidKMSKey.InvalidStateKMS key disabled / pending deletion / no grant
UnauthorizedOperationIAM or SCP denies; decode message with STS
Spot capacity-not-availableDiversify instance types and AZs

Performance problems

SymptomMetricAction
Slow after hours of load (T-series)CPUCreditBalance = 0, CPUSurplusCreditBalanceEnable Unlimited, resize, use M/C family
High iowaitEBS queue length, BurstBalanceIncrease IOPS/throughput, gp3
Network throttlingENA *_allowance_exceeded statsLarger instance, placement/limits
Memory exhaustionAgent mem_used_percentResize, fix leak, swap alarm

Lifecycle gotchas

  • Public IPv4 changes on stop/start; use Elastic IP (or DNS/ELB).
  • Instance store data is lost on stop/terminate/hardware failure.
  • Termination protection blocks API termination; ASG still can terminate unless scale-in protection is set.
  • Changing instance type requires stop; ensure ENA/NVMe drivers on the AMI for newer types.
  • For scheduled events (retirement), stop/start proactively; EventBridge can notify via Health events.

IMDSv2 enforcement

bash
aws ec2 modify-instance-metadata-options --instance-id i-0abc --http-tokens required --http-endpoint enabled
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id
```### EC2 status checks, recovery and connectivity triage

| Check | Meaning | Action |
|-------|---------|--------|
| **System status** | Underlying host/network problem | Stop/start (moves host) or auto-recover alarm |
| **Instance status** | OS-level problem (bad fstab, kernel panic, network config) | Reboot, console output, rescue volume |
| **Attached EBS status** | Volume impaired | Check volume, restore snapshot |
| **Capacity errors** | `InsufficientInstanceCapacity` | Try another AZ or type, capacity reservations |
| **Limit errors** | `InstanceLimitExceeded` | Request a Service Quotas increase |
| **`Client.UnauthorizedOperation`** | IAM denial | Decode message |

```bash
aws ec2 get-console-output --instance-id i-0abc --latest --output text
aws ec2 get-console-screenshot --instance-id i-0abc
aws cloudwatch put-metric-alarm --alarm-name recover-i-0abc --namespace AWS/EC2 --metric-name StatusCheckFailed_System \
  --dimensions Name=InstanceId,Value=i-0abc --statistic Maximum --period 60 --evaluation-periods 2 --threshold 1 \
  --comparison-operator GreaterThanOrEqualToThreshold --alarm-actions arn:aws:automate:us-east-1:ec2:recover

For an unreachable instance: stop it, detach the root volume, attach it to a rescue instance, fix the file (fstab, authorized_keys, firewall), reattach and start. EC2 Serial Console and EC2Rescue/SSM AWSSupport-ExecuteEC2Rescue help. Lost key pairs are recovered via SSM Session Manager or a rescue instance. A Pending loop usually means an EBS KMS key permission problem.

Real World Example

Scenario – instance unreachable after a reboot. A production bastion replacement stops responding after a configuration change. Instance status check shows 1/2 failed. The engineer fetches the console output and sees "Failed to mount /data" followed by emergency mode: an /etc/fstab line referencing a removed volume.

Session Manager is unavailable because the agent never started. They run AWSSupport-ExecuteEC2Rescue, which fixes the fstab entry offline, and the instance returns. The runbook now requires nofail on non-root mounts and a CloudWatch alarm on StatusCheckFailed_Instance that triggers a reboot action and notifies on-call.

Architecture Diagram

EC2 troubleshooting decision flow
Architecture
Runbook
Status checkssystem vs instance
Network / SG / keyreachable?
Console outputboot logs
EC2Rescue / SSMrepair
Recovered instance
  1. 1Read status checks to decide between an AWS-side and an in-guest problem.
  2. 2Verify security groups, NACLs, routes, public IP and key pairs.
  3. 3Use console output, screenshot or serial console to see the boot failure.
  4. 4Repair with Session Manager, EC2Rescue or a rescue instance, then add alarms to prevent recurrence.

Best Practices

  • ✓Use Session Manager so instances remain reachable without SSH; keep a Serial Console break-glass path.
  • ✓Create alarms for StatusCheckFailed_System (recover) and StatusCheckFailed_Instance (reboot).
  • ✓Use nofail in fstab for non-root volumes and test user data.
  • ✓Monitor CPU credits, EBS queue length and memory via the CloudWatch agent.
  • ✓Keep Service Quotas alarms and diversify instance types/AZs for capacity.

Common Interview Questions

Exam Tips

SOA-C03 focus

  • System check fails -> stop/start or recover; instance check fails -> reboot/fix OS.
  • InstanceLimitExceeded -> quota increase; InsufficientInstanceCapacity -> change AZ/type.
  • Unreachable instance repair -> AWSSupport-ExecuteEC2Rescue or rescue instance.
  • Burstable instance slow -> CPUCreditBalance; enable Unlimited or resize.

Finished this lesson?

0 of 46 lessons done · 0% of the course