The aws ec2 describeinstances command retrieves detailed information about Amazon EC2 instances in your account, including their current state, instance type, IP addresses, launch time, and associated security groups. It's the primary CLI tool for auditing or scripting against EC2 resources.
This command queries the AWS EC2 service using your configured credentials and returns structured JSON output. You can filter results by instance ID, state (running, stopped, pending), or tags. It's essential for automation, monitoring, and troubleshooting cloud workloads.
For example, running aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" returns only live instances. The response includes nested fields like InstanceId, InstanceType, PrivateIpAddress, and Tags.
When you run aws ec2 describeinstances, the AWS Command Line Interface (CLI) sends an HTTP request to the EC2 API endpoint. The request includes authentication headers derived from your AWS access key and secret key, or from IAM roles if running in an EC2 instance.
The EC2 service processes the request, checks permissions via IAM policies, and returns a JSON payload. The CLI formats this into readable output unless you specify --output text or --query to extract specific fields.
You can limit results using filters. For instance, --filters "Name=tag:Environment,Values=production" returns only instances tagged with Environment=production. Filters support multiple conditions and logical AND operations.
The command returns a list of reservations, each containing one or more instances. Each instance object includes:
i-1234567890abcdef0t3.medium or c5.xlargepending, running, stopping, or stoppedTo get just the instance IDs and public IPs, use:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,PublicIpAddress]' --output table
This outputs a clean table format. The --query parameter uses JMESPath syntax to select fields. Without it, the full JSON structure appears.
System administrators use this command to verify instance health during outages. A colleague once reported a web server failure; we ran describe-instances and confirmed the instance was stuck in stopping state due to a stalled shutdown process.
DevOps teams integrate it into scripts to auto-scale environments. For example, a deployment script checks if a new instance is ready by polling describe-instances until the state changes from pending to running.
Cost management tools rely on the Tags field to allocate spend. By filtering on Environment=dev, teams identify underutilized instances and shut them down after hours.
While the command itself doesn't have "types," it supports various filter combinations to narrow results. Common filters include:
| Filter Name | Value Example | Purpose |
|---|---|---|
| Name=instance-type | m5.large | Find machines of a specific size |
| Name=tag:Project | analytics-pipeline | Group instances by project name |
| Name=instance-state-name | running | List only active instances |
| Name=availability-zone | us-east-1a | Check resource distribution across zones |
Multiple filters are combined with AND logic. To find all running instances in us-east-1a tagged with Owner=team-a:
aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=running" \
"Name=availability-zone,Values=us-east-1a" \
"Name=tag:Owner,Values=team-a"
Do not confuse describe-instances with describe-instance-status. The former shows instance metadata and state; the latter returns system and instance status details, such as failed health checks or hardware issues.
Another mistake is assuming it returns all instances globally. It only returns those in the region set in your AWS CLI configuration. Run aws configure to check or change the default region.
A non-obvious point: describe-instances does not return instance root device volume details unless explicitly requested. Use --query 'Reservations[].Instances[].BlockDeviceMappings[]' to see attached volumes.
I once automated a nightly cleanup script using describe-instances to find and terminate test instances older than 24 hours. The script filtered on launch-time and state=stopped, then called stop-instances and terminate-instances in sequence.
Best practices include:
--region flag to avoid ambiguity--output json for programmatic processingUnderstanding aws ec2 describeinstances enables precise control over EC2 resources. It's foundational for managing infrastructure as code, auditing compliance, and debugging deployment failures.
Use this command to inspect, monitor, and automate your EC2 environment. It's the standard method for retrieving instance metadata across AWS environments.