When working with AWS Free Tier, you might encounter terminated EC2 instances that stubbornly remain visible in your console with error states like "Server.InternalError: Internal error on launch". These instances can't be restarted or modified, yet they clutter your instance list.
The "Server.InternalError" typically occurs when AWS's backend systems fail during instance launch. Common triggers include:
- AWS regional service disruptions
- Resource allocation failures
- Temporary capacity constraints in Free Tier
While you can't directly delete terminated instances, these methods help manage them:
// AWS CLI filter to hide terminated instances
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running"
For persistent visibility control, modify your AWS Console view:
- Navigate to EC2 Dashboard
- Click the gear icon (Preferences)
- Under "Instance Attributes", uncheck "Terminated"
For developers managing infrastructure through code, here's a Python solution using Boto3:
import boto3
def clean_ec2_view():
ec2 = boto3.client('ec2')
# List all instances (including terminated)
response = ec2.describe_instances()
# Filter out terminated instances from output
active_instances = [
instance for reservation in response['Reservations']
for instance in reservation['Instances']
if instance['State']['Name'] != 'terminated'
]
return active_instances
If terminated instances persist beyond 7 days or affect your resource limits, consider:
- Checking AWS Service Health Dashboard
- Reviewing CloudTrail logs for launch errors
- Opening a support case with the instance ID
To avoid this issue:
# Always implement instance launch error handling
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--count 1 \
--instance-type t2.micro \
--key-name MyKeyPair \
--security-group-ids sg-903004f8 \
--subnet-id subnet-6e7f829e \
--dry-run
Remember that Free Tier has specific limitations that might contribute to launch failures during peak times.
When working with AWS EC2 Free Tier, you might encounter instances that immediately transition from "pending" to "terminated" state with the error message: State Transition Reason: Server.InternalError: Internal error on launch
. This typically happens due to:
- Resource limitations in your selected Availability Zone
- Temporary AWS infrastructure issues
- Free Tier account restrictions
AWS keeps terminated instances visible in the console for about 60 minutes for diagnostic purposes. While they don't incur charges, they can clutter your instance list.
Here's how to remove them from view:
Method 1: Using AWS Console
- Navigate to EC2 Dashboard
- Select "Instances" from the left menu
- Click the gear icon (Settings) in top-right
- Uncheck "Show terminated instances"
Method 2: AWS CLI Approach
For automation, use this AWS CLI command to filter out terminated instances:
aws ec2 describe-instances --query 'Reservations[].Instances[?State.Name!=`terminated`]' --output json
Method 3: Programmatic Solution with Python
Here's a Python script using Boto3 to clean up your instance view:
import boto3
def clean_ec2_view():
ec2 = boto3.client('ec2')
response = ec2.describe_instances(
Filters=[{'Name': 'instance-state-name', 'Values': ['running', 'pending', 'stopped']}]
)
active_instances = []
for reservation in response['Reservations']:
for instance in reservation['Instances']:
active_instances.append(instance['InstanceId'])
print(f"Active instances: {active_instances}")
clean_ec2_view()
To avoid similar issues:
- Try launching in a different Availability Zone
- Check AWS Service Health Dashboard before launching
- Verify your Free Tier limits aren't exceeded
Use this CloudWatch alarm to detect failed launches:
aws cloudwatch put-metric-alarm \
--alarm-name "EC2-Launch-Failures" \
--metric-name "StatusCheckFailed_Instance" \
--namespace "AWS/EC2" \
--statistic "Sum" \
--period 60 \
--threshold 1 \
--comparison-operator "GreaterThanOrEqualToThreshold" \
--evaluation-periods 1 \
--alarm-actions "arn:aws:sns:us-east-1:123456789012:MyTopic"