Oscar Foley
Oscar Foley

Reputation: 7025

How to get a list of my AWS EC2 Instances

I need to export the list, that I get from AWS EC2 Console, of EC2 instances I have to a CSV/excel or similar.

It has to be in reports but cannot find it.

enter image description here

Upvotes: 8

Views: 42696

Answers (5)

Ramkumar
Ramkumar

Reputation: 11

#!/bin/bash

regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output text)

for region in $regions; do
    echo "Checking region: $region"
 
    aws ec2 describe-instances \
        --filters Name=instance-state-name,Values=stopped,running \
        --query "Reservations[*].Instances[*].{Region:'$region', Name:Tags[?Key==\`Name\`]|[0].Value, Instance:InstanceId, Type:InstanceType, State:State.Name}" \
        --output text \
        --region $region >> instances.csv

    echo "Finished checking region: $region"
done

This helps in getting all the instances in the account using AWS CLI.

Upvotes: 0

kgiannakakis
kgiannakakis

Reputation: 104196

With the AWS CLI you can use the following command (Linux):

aws ec2 describe-instances \
    --filters Name=instance-state-name,Values=running \
    --query 'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`]|[0].Value,Instance:InstanceId,Type:InstanceType}' \
    --output text >> instances.csv

This will export the instance fields in tab-separated lines that you can later import into Excel.

Upvotes: 11

user17221030
user17221030

Reputation: 71

The easiest way I have found is to configure your view with all the fields you want, then, select (highlight with mouse) all the fields and copy and paste them into excel

Upvotes: 7

romanzpolski
romanzpolski

Reputation: 39

You can export list of all your instances as csv using Resource Groups & Tag Editor!

I can't find a way to filter by Instant State though, I'm not sure if this is possible.

AWS console screenshot

Upvotes: 0

Vikyol
Vikyol

Reputation: 5665

You can use Resource Groups.

  1. Resource Types: AWS::EC2::instance
  2. Search resources
  3. Export search results to CSV

Update 11/2020: It is not possible to list all resources by type any longer. You have to either specify tags or Cloudformation stacks to create a resource group.

Upvotes: 7

Related Questions