AWS CLI: Retrieve list of running EC2 instance types

Viewed 1526

I am trying a quick way to list/output all instances type running in my environment. Nothing else just a list of those InstanceType.

I can easily get them on the console but it's a bit time consuming.

Thanks in advance!

3 Answers

AWS CLI -

aws ec2 describe-instances --region eu-west-1 --query 'Reservations[*].Instances[*].InstanceType' --output text | sort | uniq

In AWS web console - You can also use AWS Config -> Advanced queries -> Query editor as shown below. Output can be exported as json or csv. Also have aws cli for this.

enter image description here

Personally I use Steampipe to query AWS (and other cloud) resources using SQL from my terminal. Per your question, I've also limited resources to those "running":

select
  instance_type,
  count(*)
from
  aws_ec2_instance
where
  instance_state = 'running'
group by
  instance_type
order by
  count

I think this maybe help you:

aws ec2 describe-instances \
--query "Reservations[*].Instances[*].[InstanceType]" \
--output json
Related