Amazon EC2 Operations: Instance Lifecycle, Status Checks, Auto Recovery, Placement Groups, AMIs and Troubleshooting
Instance Lifecycle
| State / action | What happens | Billing and data |
pending → running | Launching | Compute billed per second once running (Linux, minimum 60 s) |
| Stop | Shuts down OS. Instance can start later on a possibly different host | No compute charge. EBS volumes keep data and are billed. Instance store data is lost. Public IPv4 changes (unless Elastic IP). Private IP is kept |
| Reboot | OS restart on the same host | Same host, same IPs, instance store kept |
| Hibernate | Saves RAM to the encrypted root EBS volume, then stops. Resumes with processes intact | Needs an encrypted root volume large enough for RAM and supported instance types/AMIs |
| Terminate | Deletes the instance | Root EBS volume deleted by default (DeleteOnTermination). Additional volumes kept by default. Termination protection blocks accidental terminate |
| Retire (AWS event) | Host hardware is failing | Stop and start (EBS-backed) to move to a healthy host before the date |
bash
aws ec2 stop-instances --instance-ids i-0abc
aws ec2 start-instances --instance-ids i-0abc
aws ec2 modify-instance-attribute --instance-id i-0abc --disable-api-termination # termination protection
aws ec2 modify-instance-attribute --instance-id i-0abc --instance-type "{\"Value\": \"m6i.large\"}" # resize: instance must be stopped
aws ec2 describe-instance-status --instance-ids i-0abc --include-all-instances
Resize steps To change the instance type: stop → modify → start. The new type must be compatible with the AMI (architecture, virtualization, ENA and NVMe drivers). EBS data is kept. Expect a short outage.
Status Checks
| Check | Detects | Typical fix |
| System status check | Problems with the AWS side: host hardware, power, network, hypervisor | Stop and start the instance (moves it to new hardware) or use auto recovery. Reboot does not move it |
| Instance status check | Problems with your instance: bad OS config, exhausted memory, corrupted file system, wrong kernel/network config | Reboot or fix the OS (use Systems Manager or detach the volume and repair it from another instance) |
| Attached EBS status check | EBS volume impaired | Replace or restore the volume from a snapshot |
Metrics: StatusCheckFailed, StatusCheckFailed_System, StatusCheckFailed_Instance (0 = pass, 1 = fail) in AWS/EC2, every minute.
Auto Recovery
A CloudWatch alarm on **StatusCheckFailed_System can run the recover action. AWS moves the instance to new hardware with the same instance id, private IP, Elastic IP and metadata. It does not work for instance-store instances. Many newer instances have simplified automatic recovery** on by default.
bash
aws cloudwatch put-metric-alarm --alarm-name recover-web1 --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:ap-south-1:ec2:recover arn:aws:sns:ap-south-1:111111111111:ops
- Other alarm actions:
ec2:stop, ec2:terminate, ec2:reboot
- For fleets prefer Auto Scaling with ELB health checks, so unhealthy instances are replaced automatically
Instance Types and Sizing
| Family | Use |
t3/t4g (burstable) | Low average CPU with bursts. Uses CPU credits. Watch CPUCreditBalance. Unlimited mode avoids throttling but can add cost |
m general purpose | Balanced |
c compute optimized | Batch, web servers, encoding |
r, x memory optimized | Databases, in-memory caches |
i, d storage optimized | High local IOPS, data warehouses |
g, p, inf, trn accelerated | GPU, ML |
Suffix g (m7g), a (AMD), i (Intel), n (network), d (local NVMe) | Variants. Graviton (arm64) gives good price-performance but needs arm64 builds |
Purchasing Options
| Option | Notes |
| On-Demand | No commitment, per-second billing |
| Savings Plans (Compute / EC2 Instance) | 1 or 3 year spend commitment. Compute Savings Plans also cover Fargate and Lambda and are flexible across families and Regions |
| Reserved Instances | Commit to instance attributes. Standard or Convertible. Zonal RIs reserve capacity in an AZ |
| Spot | Spare capacity at deep discounts. 2-minute interruption notice (EventBridge and instance metadata). Use for stateless, fault-tolerant work |
| Dedicated Hosts / Instances | Single-tenant, for licensing or compliance |
| On-Demand Capacity Reservations | Reserve capacity in an AZ without a term commitment. Combine with Savings Plans for the discount |
Placement Groups
| Type | Behavior | Use |
| Cluster | Packed in one AZ on close hardware for low latency and high throughput | HPC, tightly coupled. Higher risk: one hardware fault can hit many |
| Spread | Each instance on separate hardware (max 7 per AZ per group) | A few critical instances that must not fail together |
| Partition | Groups of instances on separate racks (up to 7 partitions per AZ) | Large distributed systems like Hadoop, Cassandra, Kafka |
- Launch instances of the same type together to avoid
InsufficientInstanceCapacity in cluster groups
- You can move an instance into a group by stopping it first
AMIs
- An AMI = root volume snapshot + launch permissions + block device mapping. It is Regional
- Create from an instance (
create-image), which snapshots attached volumes. Copy to another Region (and re-encrypt with a different KMS key). Share with accounts or make public (avoid). Deregister an AMI, then delete its snapshots separately
- Keep a golden AMI with patches and agents (SSM agent, CloudWatch agent). Automate with EC2 Image Builder
- Use SSM Parameter Store public parameters to get the latest Amazon Linux AMI id:
/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64
bash
aws ec2 create-image --instance-id i-0abc --name "web-golden-2026-11-17" --no-reboot
aws ec2 copy-image --source-region ap-south-1 --source-image-id ami-0abc --name web-golden --region ap-southeast-1 --encrypted
aws ec2 modify-image-attribute --image-id ami-0abc --launch-permission "Add=[{UserId=222222222222}]"
aws ec2 deregister-image --image-id ami-0old
Networking Attributes
| Item | Notes |
| Elastic IP | Static public IPv4 you own until released. Charged when not attached (and public IPv4 addresses are charged in general now). Re-map to another instance for quick failover |
| ENI (elastic network interface) | Virtual NIC with private IPs, security groups, MAC. Can be moved between instances in the same AZ (a secondary ENI keeps an IP for failover or licensing) |
| Enhanced networking (ENA) | High bandwidth, low latency on supported types |
| Source/destination check | Disable on NAT or firewall instances so they can forward traffic |
User Data and Metadata
- User data runs at first boot (cloud-init). Logs in
/var/log/cloud-init-output.log
- Instance metadata at
169.254.169.254. Use IMDSv2 (token required). Enforce with --metadata-options HttpTokens=required or an SCP
Connection Troubleshooting
| Symptom | Check |
| SSH timeout | Security group port 22 from your IP, NACL (both directions), route to Internet Gateway, public IP, instance running. Better: use Session Manager |
Permission denied (publickey) | Wrong key pair or user (ec2-user, ubuntu, admin), key file permissions chmod 400 |
Connection refused | Service not listening on that port |
| RDP failure | Port 3389 allowed, correct password, Windows firewall |
| Session Manager does not connect | SSM Agent running, instance profile with AmazonSSMManagedInstanceCore, network path to SSM endpoints (internet, NAT or VPC endpoints ssm, ssmmessages, ec2messages) |
Instance launch fails InsufficientInstanceCapacity | Try another AZ or type, wait, or use a capacity reservation |
InstanceLimitExceeded / VcpuLimitExceeded | Request a quota increase |
| Instance terminates immediately | Encrypted volume with KMS key access problem, EBS limit reached, snapshot missing |
| Cannot reach instance after changing config | Use the EC2 serial console or detach the root volume, attach to a rescue instance and fix files |
Practice Tasks
- Launch an instance, stop and start it, and note which IP changes
- Create a status check alarm with the recover action
- Create an AMI, copy it to another Region and launch from it
- Change the instance type of a stopped instance
- Connect with Session Manager and then close port 22 completely
Conclusion
Know the EC2 lifecycle (stop vs terminate vs hibernate), the difference between system status checks (AWS side: stop/start or recover) and instance status checks (your OS: reboot or fix), set recovery alarms or use Auto Scaling health replacement, pick the right purchase option and placement group, manage AMIs per Region, and use Session Manager and the troubleshooting table when connections fail.
Quick Summary: lifecycle; status checks; auto recovery; types; purchasing; placement groups; AMIs; networking; metadata; troubleshooting.