← Back to Playbooks
    SEV-2AWS

    EC2 Instance Failure Playbook

    Instance unreachable, status check failures, EBS volume detachment, or unexpected termination. EC2 failures range from single-instance issues to availability zone–wide events. This playbook covers rapid diagnosis, recovery, and prevention for the most common EC2 failure modes.

    Operator's Field Notes

    Jeremy Martinez · Incident Commander | Principal Site Reliability Engineer

    "EC2 instance failures are deceptive. The instance looks 'running' in the console but is completely unreachable. Or it's responding to health checks but the application inside is wedged. The first thing I always do is check both status checks - the system status check (AWS infrastructure) and the instance status check (your OS). That distinction tells you whether this is AWS's problem or yours."

    "The biggest mistake I see teams make is immediately trying to SSH into a failing instance. If the system status check is failing, SSH won't work and you're wasting time. Stop-start (not reboot) to migrate to new hardware, or launch a replacement from your AMI. If the instance status check is failing, that's an OS-level problem - check the system log via the console."

    "Always check the AWS Health Dashboard and your region's status. If you're seeing failures across multiple instances in the same AZ, it's likely an AWS infrastructure event, and your playbook shifts to cross-AZ failover rather than individual instance recovery."

    EC2 FAILURE SYMPTOM MATRIX

    Direct Symptoms

    • • Instance status: impaired or insufficient-data
    • • System status check: failed
    • • SSH connection timeout or refused
    • • EBS volume status: io-enabled: false
    • • CloudWatch metrics gap (no data points)
    • • Instance state: stopped unexpectedly

    Indirect / Misleading Symptoms

    • • ALB/NLB targets draining or unhealthy
    • • Application errors from downstream services
    • • Auto Scaling group launching replacements
    • • ECS/EKS tasks being rescheduled
    • • Spot instance interruption (2-min warning)
    • • Scheduled maintenance event notification

    First 5 Minutes - Triage

    1. Check Instance Status

    # Check both status checks
    aws ec2 describe-instance-status --instance-ids i-0abc123def456
    # Look for:
    #   SystemStatus: "ok" or "impaired"
    #   InstanceStatus: "ok" or "impaired"
    
    # Quick overview of all instances in region
    aws ec2 describe-instance-status --filters Name=instance-status.status,Values=impaired

    2. Get System Log (Console Output)

    # Get the system log - crucial for boot failures
    aws ec2 get-console-output --instance-id i-0abc123def456
    
    # Look for:
    #   - Kernel panic messages
    #   - Filesystem errors (fsck failures)
    #   - OOM killer messages
    #   - Network interface initialization failures
    #   - Cloud-init errors

    3. Check EBS Volume Status

    # Check volume attachment status
    aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=i-0abc123def456
    
    # Check for degraded volumes
    aws ec2 describe-volume-status --volume-ids vol-0abc123def456
    
    # Look for:
    #   - io-enabled: false (IO suspended)
    #   - Status: impaired
    #   - Events: potential-data-inconsistency

    4. Check AWS Health Dashboard

    # Check for ongoing AWS events affecting your account
    aws health describe-events --filter "eventTypeCategories=issue,scheduledChange"
    
    # Check Personal Health Dashboard for your specific resources
    aws health describe-affected-entities --filter "eventArns=arn:aws:health:..."

    Decision Tree - What Type of Failure?

    System Status Check Failed

    AWS hardware or infrastructure problem

    • → Stop and start the instance (migrates to new hardware)
    • → Do NOT reboot - reboot keeps the same hardware
    • → If instance-store backed, launch replacement from AMI
    • → If AZ-wide issue, fail over to another AZ

    Instance Status Check Failed

    OS-level problem on your instance

    • → Check system log for kernel panics or OOM
    • → Try reboot first
    • → If boot fails, detach root volume, attach to recovery instance
    • → Fix filesystem issues, then reattach

    Instance Running but Unreachable

    Network or security group issue

    • → Check security groups and NACLs
    • → Verify route tables and internet gateway
    • → Check if Elastic IP is still attached
    • → Use SSM Session Manager as alternative access

    Recovery Procedures

    Stop-Start Migration (Hardware Failure)

    # IMPORTANT: This changes the public IP unless you have an Elastic IP
    # Stop the instance
    aws ec2 stop-instances --instance-ids i-0abc123def456
    
    # Wait for stopped state
    aws ec2 wait instance-stopped --instance-ids i-0abc123def456
    
    # Start on new hardware
    aws ec2 start-instances --instance-ids i-0abc123def456
    
    # Wait for running + status checks
    aws ec2 wait instance-status-ok --instance-ids i-0abc123def456
    
    # If stop-start fails, try force-stop
    aws ec2 stop-instances --instance-ids i-0abc123def456 --force

    Root Volume Recovery

    # If the instance won't boot due to filesystem corruption:
    
    # 1. Stop the failed instance
    aws ec2 stop-instances --instance-ids i-FAILED
    
    # 2. Detach root volume
    aws ec2 detach-volume --volume-id vol-ROOT --instance-id i-FAILED
    
    # 3. Launch a recovery instance in the same AZ
    aws ec2 run-instances --image-id ami-AMAZON-LINUX --instance-type t3.micro \
      --placement AvailabilityZone=us-east-1a
    
    # 4. Attach the root volume as secondary to recovery instance
    aws ec2 attach-volume --volume-id vol-ROOT --instance-id i-RECOVERY --device /dev/xvdf
    
    # 5. SSH to recovery instance and fix
    ssh ec2-user@i-RECOVERY
    sudo mkdir /mnt/recovery
    sudo mount /dev/xvdf1 /mnt/recovery
    # Fix fstab, repair filesystem, check logs, etc.
    sudo umount /mnt/recovery
    
    # 6. Reattach to original instance and start
    aws ec2 detach-volume --volume-id vol-ROOT --instance-id i-RECOVERY
    aws ec2 attach-volume --volume-id vol-ROOT --instance-id i-FAILED --device /dev/xvda
    aws ec2 start-instances --instance-ids i-FAILED

    SSM Session Manager (When SSH Fails)

    # Connect via SSM (requires SSM agent running + IAM role)
    aws ssm start-session --target i-0abc123def456
    
    # Run commands remotely without SSH
    aws ssm send-command --instance-ids i-0abc123def456 \
      --document-name "AWS-RunShellScript" \
      --parameters 'commands=["dmesg | tail -50", "df -h", "free -m"]'
    
    # Get command output
    aws ssm get-command-invocation --command-id CMD_ID --instance-id i-0abc123def456

    Launch Replacement Instance

    # If recovery isn't feasible, launch from latest AMI
    # Find your most recent AMI
    aws ec2 describe-images --owners self --filters "Name=name,Values=myapp-*" \
      --query 'sort_by(Images, &CreationDate)[-1]'
    
    # Launch replacement
    aws ec2 run-instances --image-id ami-LATEST --instance-type m5.xlarge \
      --subnet-id subnet-ALT-AZ --security-group-ids sg-APP \
      --iam-instance-profile Name=MyAppRole \
      --user-data file://bootstrap.sh
    
    # Register with load balancer
    aws elbv2 register-targets --target-group-arn TG_ARN \
      --targets Id=i-NEW

    Spot Instance Interruptions

    Spot interruptions give you a 2-minute warning. Your architecture should handle this gracefully.

    # Check for spot interruption notices (from instance metadata)
    curl -s http://169.254.169.254/latest/meta-data/spot/instance-action
    
    # Typical response when interrupted:
    # {"action": "terminate", "time": "2024-01-15T12:00:00Z"}
    
    # CloudWatch Events rule for spot interruptions:
    {
      "source": ["aws.ec2"],
      "detail-type": ["EC2 Spot Instance Interruption Warning"],
      "detail": {
        "instance-action": ["terminate"]
      }
    }

    Mitigation strategies:

    • • Use Spot Fleet with capacity-optimized allocation
    • • Implement graceful shutdown handlers (SIGTERM)
    • • Checkpoint work to S3/DynamoDB on interruption
    • • Use mixed instance types across multiple AZs
    • • Keep on-demand baseline with spot for burst

    EBS Volume Issues

    Volume Stuck in Attaching/Detaching

    # Check volume attachment state
    aws ec2 describe-volumes --volume-ids vol-0abc123 \
      --query 'Volumes[].Attachments[].State'
    
    # Force detach (DANGEROUS - can cause data corruption)
    aws ec2 detach-volume --volume-id vol-0abc123 --force
    
    # If volume is stuck in "in-use" after instance terminated:
    # Wait 10 minutes, then force detach

    EBS Performance Degradation

    # Check CloudWatch for EBS metrics
    aws cloudwatch get-metric-statistics --namespace AWS/EBS \
      --metric-name VolumeQueueLength --dimensions Name=VolumeId,Value=vol-0abc123 \
      --start-time $(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%S) \
      --end-time $(date -u +%Y-%m-%dT%H:%M:%S) --period 300 --statistics Average
    
    # High QueueLength = IO bottleneck
    # Check if burst balance is depleted (gp2/gp3)
    # Metric: BurstBalance - if 0%, volume is throttled
    
    # Solutions:
    # - Upgrade volume type (gp2 → gp3, gp3 → io2)
    # - Increase volume size (gp2 baseline = 3 IOPS per GB)
    # - Enable io2 Block Express for extreme performance

    Auto Scaling Interactions

    Auto Scaling can mask EC2 failures by replacing instances, but it can also cause cascading problems.

    # Check ASG activity for recent launches/terminations
    aws autoscaling describe-scaling-activities --auto-scaling-group-name my-asg \
      --max-items 20
    
    # Check if ASG is in a launch-fail loop
    # Look for repeated: "Launching a new EC2 instance" → "instance failed health check"
    
    # Temporarily suspend health check replacement to investigate
    aws autoscaling suspend-processes --auto-scaling-group-name my-asg \
      --scaling-processes HealthCheck ReplaceUnhealthy
    
    # IMPORTANT: Remember to resume after fixing
    aws autoscaling resume-processes --auto-scaling-group-name my-asg \
      --scaling-processes HealthCheck ReplaceUnhealthy

    Prevention & Hardening

    Infrastructure Design

    • • Multi-AZ deployment with auto failover
    • • Auto Scaling with health checks (ELB, not EC2)
    • • Immutable infrastructure (replace, don't repair)
    • • Instance metadata tags for role identification
    • • SSM agent on all instances for backup access

    Monitoring & Alerting

    • • CloudWatch alarms on both status checks
    • • Auto-recover action on system status failure
    • • EBS volume status monitoring
    • • Spot interruption handler (EventBridge)
    • • Personal Health Dashboard notifications

    Backup & Recovery

    • • Regular AMI snapshots (automated via DLM)
    • • EBS snapshots with lifecycle policies
    • • Launch templates (not launch configurations)
    • • Cross-AZ and cross-region snapshot copies
    • • Tested recovery runbooks

    Auto Recovery Setup

    # CloudWatch alarm for auto-recovery
    aws cloudwatch put-metric-alarm \
      --alarm-name "EC2-AutoRecover" \
      --metric-name StatusCheckFailed_System \
      --namespace AWS/EC2 \
      --dimensions Name=InstanceId,Value=i-0abc123 \
      --statistic Maximum --period 60 \
      --evaluation-periods 3 --threshold 1 \
      --comparison-operator GreaterThanOrEqualToThreshold \
      --alarm-actions arn:aws:automate:us-east-1:ec2:recover

    Anti-Patterns

    ❌ Don't Do This

    • • Rebooting when system status check fails
    • • SSHing to a failing instance as first step
    • • Force-detaching EBS without stopping writes
    • • Running in a single AZ
    • • No AMI backup strategy
    • • Relying solely on SSH for access

    ✅ Do This Instead

    • • Stop-start to migrate hardware
    • • Check status checks + console output first
    • • Graceful unmount, then detach
    • • Multi-AZ with auto scaling
    • • Automated AMI + EBS snapshot lifecycle
    • • SSM Session Manager as backup access

    Communication Templates

    Initial Status Update

    INCIDENT: EC2 Instance Failure
    SEVERITY: SEV-2
    STATUS: Investigating
    
    IMPACT: [Service name] experiencing degraded performance / unavailability.
            [X] instances in [AZ] are impaired.
    
    CAUSE: EC2 [system/instance] status check failure detected at [time].
           AWS Health Dashboard: [shows/does not show] related events.
    
    ACTIONS IN PROGRESS:
    - Assessing scope of impact across availability zones
    - Initiating [stop-start recovery / replacement launch]
    - Monitoring Auto Scaling group activity
    
    NEXT UPDATE: 15 minutes