Skip to content

Aws cleanup


title: AWS billing investigation and EC2 cleanup description: Incident record from September 2026: tracing an unexpected AWS bill to an orphaned EC2 instance and removing its resources. audience: internal type: explanation owner: platform-team last_reviewed: 2026-11-19


Summary

An unexpected AWS bill of USD 42.68 month-to-date was investigated. The cost was traced to an EC2 instance named "ios" (i-0b39b0db94fc3b3ed, Red Hat Enterprise Linux, t3.micro, region ap-southeast-7 / Asia Pacific Thailand) that had been running continuously all month, plus two idle public IPv4 addresses and a Route 53 hosted zone. The original SSH key (.pem) for this instance was lost — the team member who created it had left without sharing the key. After exhausting browser-based access options, the decision was made to terminate all related resources rather than recover access. Post-cleanup billing dropped from ~$1.25–1.50/day to near-zero.

How to check AWS costs (Console)

  1. Billing home: Account name (top right) → Billing and Cost Management. Shows current month total and a quick service breakdown.
  2. Cost Explorer: Billing and Cost Management → Cost Explorer. Set date range and granularity (Daily recommended for recent activity), group by Service to see which service is costing what, over any time window.
  3. Bills: Billing and Cost Management → Bills → select a month. Scroll to "AWS service charges" / "Charges by service" — this is the fully itemized, expandable tree (Description / Usage Quantity / Amount in USD) showing exact usage type and cost per line, e.g. $0.0407 per On-Demand RHEL t3.micro Instance Hour.

Note the difference between month-to-date totals and a single day's total shown on some dashboard widgets — comparing the wrong two numbers (e.g., "today only" vs "whole month") is a common source of confusion when numbers on different pages don't match.

Root cause of the $42.68 charge

Service Cost Cause
Elastic Compute Cloud $31.95 t3.micro running RHEL, ~742 hrs (essentially the whole month) in ap-southeast-7 (Thailand), plus 20 GB gp3 EBS volume
Virtual Private Cloud $7.44 Two public IPv4 addresses (Singapore + Thailand) billed at $0.005/hr each, all month — AWS bills for public IPv4 addresses (idle or in-use) since Feb 2024
Route 53 $3.25 Hosted zone base charge + DNS queries
Data Transfer / S3 / Certificate Manager ~$0.04 Negligible

Lost SSH key — diagnosis path

The original .pem key pair for the "ios" instance was not available (the person who launched the instance had left). Browser-based, key-less access methods were attempted in order:

  1. EC2 Instance Connect (Console → instance → Connect → "EC2 Instance Connect" tab). Failed with: Failed to connect to your instance — Error establishing SSH connection to your instance. Try again later.
  2. Security group inbound rules were confirmed open on port 22 (0.0.0.0/0), ruling out the network as the cause.
  3. Instance status checks passed (3/3), ruling out instance health.
  4. Conclusion: the RHEL AMI in use (RHEL-10.0.0_HVM-20250918-x86_64-0-Hourly2-GP3, official Red Hat owner ID <AWS_ACCOUNT_ID>, confirmed legitimate) most likely does not have the EC2 Instance Connect agent installed/running — this is common on official RHEL images, unlike Amazon Linux which includes it by default.

  5. AWS Systems Manager Session Manager (a different, non-SSH connection mechanism). Requires an IAM role with the AmazonSSMManagedInstanceCore policy attached to the instance.

  6. Created role EC2-SSM-Role (IAM → Roles → Create role → AWS service → EC2 → attach AmazonSSMManagedInstanceCore policy).
  7. Attached it via EC2 → instance → Actions → Security → Modify IAM role.
  8. After waiting several minutes, the instance still did not appear in Systems Manager → Session Manager → Start session.
  9. Region, IAM role, instance health, and networking were all confirmed correct — pointing to the SSM Agent also not being active on this instance.

  10. Remaining recovery option (not executed): the standard AWS EBS-volume workaround — stop the instance, detach its root volume, attach it to a temporary helper instance with a working key, mount the volume, inject a new SSH public key into ~/.ssh/authorized_keys (or enable the SSM Agent via chroot), then reattach the volume and restart. This is the documented, non-destructive way to regain access to an instance with a lost key, without any data loss.

Decision: full teardown instead of recovery

Given ongoing cost accrual and no confirmed critical data on the instance, the decision was made to terminate/delete all related resources rather than perform the recovery workaround.

Cleanup steps performed

  1. Terminate EC2 instances — EC2 console → select instance(s) → Instance state → Terminate instance. Terminated both "ios" (i-0b39b0db94fc3b3ed) and a second stopped instance, "test" (i-02d9e01651b204671).
  2. Terminating deletes the root EBS volume (default "delete on termination") permanently — this is irreversible.
  3. Check/release Elastic IPs — VPC console → Elastic IPs, checked in every region that had billed usage (Thailand, Singapore). In this case none were found as persistent Elastic IPs — the billed IPv4 addresses were auto-assigned to the instances and were released automatically upon termination, at no extra step.
  4. Delete Route 53 hosted zone — Route 53 → Hosted zones → select zone → Delete.
  5. First attempt failed: "The specified hosted zone contains non-required resource record sets and so cannot be deleted."
  6. Fix: open the zone, delete every record except the mandatory NS and SOA records, then delete the zone itself.
  7. Only do this if no live domain/service still depends on that DNS zone.

Verifying the teardown is complete

  • EC2 → Instances: confirm state is "Terminated" (disappears from the default list after ~1 hour).
  • EC2 → Volumes: confirm no orphaned "available" (unattached) volumes remain.
  • VPC → Elastic IPs: confirm empty in every region used.
  • Route 53 → Hosted zones: confirm the zone no longer appears.
  • Resource Groups → Tag Editor (Region: All regions, Resource types: All): the fastest way to see literally every remaining resource in the account at once.
  • Billing → Cost Explorer, daily granularity, last 7 days, grouped by service: the definitive check. Note that billing data lags ~24 hours, so the day of cleanup itself will still show partial charges (prorated cost for the hours resources existed before deletion) — the real confirmation is a full day after cleanup showing $0.00 for EC2, Route 53, and VPC.
  • Result observed the next check: total pre-tax charges for the day dropped to $1.18 (from $42.68 for the prior period), with the residual $0.60 Route 53 / $0.46 EC2 / $0.12 VPC amounts confirmed to be the tail end of partial-day usage before deletion, not new ongoing charges.

Lessons learned / recommendations for future EC2 setups

  1. Never let a single person be the only holder of an instance's key pair. Store .pem files in a shared password manager (1Password, Bitwarden, etc.) or team secrets vault immediately after creation.
  2. Attach an IAM instance role with AmazonSSMManagedInstanceCore at launch time, and confirm the SSM Agent is running (systemctl status amazon-ssm-agent) right after first boot. This makes Session Manager available from day one — no key file ever needed, and no single point of failure.
  3. Prefer AMIs with EC2 Instance Connect pre-installed (e.g., Amazon Linux) when browser-based, key-less SSH access is desired, or explicitly install/enable the agent on other distros (RHEL, Ubuntu) right after launch.
  4. Release or avoid unused public IPv4 addresses. AWS bills $0.005/hr per public IPv4 (idle or in-use) since Feb 2024 — stop instances or release Elastic IPs when not needed to avoid silent, continuous charges.
  5. Set a Billing Budget alert (Billing → Budgets) so unexpected month-long charges like this are caught within days, not discovered at month-end.
  6. Tag every resource (e.g., Owner, Project, CreatedBy) at creation time — this would have made it immediately clear who created "ios" and let the team ask that person for the key before they left.