Troubleshoot Ec2 Instance Credit Depletion [Solved]

Issue Key Symptom Primary Fix
CPU Credit Depletion Sudden drop in performance / 10% CPU cap Switch to T3/T4g Unlimited or Upgrade Instance
Rogue Processes Unexpected CPU spikes in CloudWatch Terminate high-CPU tasks via top
Small Instance Size Baseline performance is too low Upsize instance (e.g., t3.micro to t3.medium)

Troubleshooting AWS EC2 CPU credit depletion dashboard and server performance.

What is EC2 Instance Credit Depletion?

EC2 instance credit depletion occurs when burstable performance instances (T2, T3, T3a, and T4g) exhaust their earned CPU credits. AWS designs these instances to provide a baseline level of CPU performance with the ability to “burst” above that level when needed.

Think of CPU credits like a battery. When your instance is idle or running below its baseline, it charges the battery. When demand spikes, it consumes those credits. If the “battery” hits zero, AWS throttles your instance performance strictly to its baseline level, which often feels like the server has crashed or frozen.

This “battery drain” is common for developers using free-tier instances or small production workloads that haven’t been scaled correctly for their actual traffic patterns.

Step-by-Step Solutions

1. Monitor CPU Credit Balance in CloudWatch

The first step is to confirm that credit exhaustion is the actual cause of the slowdown. You need to check your CloudWatch metrics.

Navigate to the CloudWatch console and look for the following metrics under EC2:

  • CPUCreditBalance: The number of credits currently available.
  • CPUCreditUsage: The rate at which credits are being consumed.

If CPUCreditBalance is at or near zero, your performance issues are directly tied to credit depletion.

2. Identify Resource-Hogging Processes

If your credits are draining faster than expected, a rogue process might be taxing your CPU. Connect to your instance via SSH and run the following command:

# View real-time resource usage sorted by CPU
top -o %CPU

# Or use htop for a more visual interface
sudo apt install htop && htop

Look for processes consuming more than 10-20% of the CPU consistently. If you find a process that shouldn’t be running, you can kill it using its PID (Process ID):

kill -9 [PID_NUMBER]

3. Enable T2/T3 Unlimited Mode

If your workload periodically requires high CPU but you don’t want to upgrade to a larger instance, you can enable “Unlimited Mode.” This allows the instance to burst beyond the baseline even if the credit balance is zero, though you will be charged a small fee per vCPU-hour.

You can enable this via the AWS CLI:

aws ec2 modify-instance-credit-specification \
    --instance-credit-specification "InstanceId=i-1234567890abcdef0,CpuCredits=unlimited"

4. Upgrade the Instance Type

If your instance is constantly running out of credits, it means your “baseline” requirement is higher than what a burstable instance provides. The most stable solution is to upgrade to an instance with a higher baseline (like a larger T3 size) or a non-burstable type (like the M5 or C5 series).

To upgrade, stop the instance, change the instance type in the console settings, and start it again.