Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

Spot instances disappear and the state reason is `Server.SpotInstanceTermination`.

IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → AWS reclaimed the Spot capacity. You get a 2-minute interruption notice, and possibly an earlier rebalance recommendation.

Diagnose →

aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].StateReason'
aws ec2 describe-spot-instance-requests --filters Name=instance-id,Values=i-0abc \
  --query 'SpotInstanceRequests[].Status'
# on the instance, the notice endpoint:
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/spot/instance-action

Fix →

  1. Diversify across many instance types and all AZs, and use the price-capacity-optimized allocation strategy
  2. Handle the interruption notice: drain from the LB and checkpoint work. On EKS, use Karpenter or the Node Termination Handler
  3. Turn on Capacity Rebalancing on the ASG

Prevent → Run only stateless, interruptible workloads on Spot, and keep an On-Demand base capacity for the minimum.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing