

How to export Amazon EC2 instances to a CSV file
source link: https://thehftguy.com/2016/03/10/how-to-export-amazon-ec2-instances-to-a-csv-file/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The HFT Guy
A developer in London
Amazon website is limited to 50 instances per page. Viewing lots of instances is a pain and it doesn’t support exporting to CSV/TSV/Excel/other out of the box. The only fix is to use the CLI.
Requirements
- An AWS account with access rights to see your servers
- A pair of AWS keys (Users -> [username] -> Security Credentials -> Create Access Key)
# Install AWS packages
sudo
apt-get
install
-y python python-pip
sudo
pip
install
aws-shell
Listing Instances
# aws-shell will show a wizard to configure your account and region the first time you use it
aws-shell
ec2 describe-instances --output text --query
'Reservations[*].Instances[*].[InstanceId, InstanceType, ImageId, State.Name, LaunchTime, Placement.AvailabilityZone, Placement.Tenancy, PrivateIpAddress, PrivateDnsName, PublicDnsName, [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`purpose`].Value] [0][0], [Tags[?Key==`environment`].Value] [0][0], [Tags[?Key==`team`].Value] [0][0] ]'
> instances.tsv
# open instances.tsv with Excel
# enjoy
You can modify the command to pick the information you want. Refer to the official AWS command line reference.
Post navigation
5 thoughts on “How to export Amazon EC2 instances to a CSV file”
-
chodesuresh says:
thanks that works. If you want to get instances with name in tabular format use the below command
aws ec2 describe-instances –output text –query ‘Reservations[*].Instances[*].[InstanceId, State.Name, [Tags[?Key==`Name`].Value] [0][0] ]’ –output table
-
john nicholson says:
Thank you very much HFT guy for this tip! I was asked to generate a list our AWS instances for coporate SecOps team, and found I could not simply export from console. I had to change ‘ to ” before Reservations and at the end before the >. But this worked for me. I ran it from from a windows 10 laptop with AWS CLI installed. Note also, I used –profile to supply the aws credentials needed for our awsprod environment (we have a test/dev environment too :
aws –profile awsprod ec2 describe-instances –output text –query “Reservations[*].Instances[*].[InstanceId, InstanceType, ImageId, State.Name, LaunchTime, Placement.AvailabilityZone, Placement.Tenancy, PrivateIpAddress, PrivateDnsName, PublicDnsName, [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`purpose`].Value] [0][0], [Tags[?Key==`environment`].Value] [0][0], [Tags[?Key==`team`].Value] [0][0] ]” > c:\instances.tsv -
Corey Hallisey says:
Any way to include a first row of column headers in the output?
-
Sergey says:
aws ec2 describe-instances –query ‘Reservations[*].Instances[*].{Internal_IP:NetworkInterfaces[0].PrivateIpAddresses[0].PrivateIpAddress,Instance_ID:InstanceId,Instance_name:Tags[?Key==`Name`]|[0].Value,Region:Placement.AvailabilityZone,PublicDNS:PublicDnsName,KeyName:KeyName,Type_of_instance:InstanceType,Public_IP:PublicIpAddress}’ –output table
-
-
Luke Rawlins says:
This is definitely going to come in handy! Thanks!
Leave a Reply Cancel reply
Recommend
-
6
Performance Tuning Linux Instances on EC2 03 Mar 2015 At the last AWS re:Invent, I gave a talk on "Performance Tuning EC2 Instances", where I showed how my team (Performance and Reliability Engineering) tunes Linux EC2 insta...
-
9
Ansible at Grofers (Part 3) — Managing EC2 Instances
-
10
Repeatable performance tests: EC2 instances are neither good nor bad |
-
18
Abstract This post provides an overview of Amazon EC2 Spot Instances, as well as best practices for using them on AWS EKS effectively Table Of Contents 🚀 What to know about spo...
-
5
AWS Introduces Amazon EC2 VT1 Instances for Video Transcoding Sep 20, 2021...
-
11
How Netflix Tunes EC2 Instances for Performance 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How Netflix Tunes EC2 Instan...
-
5
PostgreSQL on ARM-based AWS EC2 Instances: Is It Any Good? Back to the Blog The expected growth of ARM processors in data centers has been a hot topic for discussion for...
-
8
NAKIVO Blog > Cloud > Creating an SSH Connection with Amazon EC2 Instance Connect...
-
8
Amazon EC2 Introduces Automatic Recovery of Instances by Default Apr 24, 2022...
-
10
Export data into CSV file in PHP 640 views 10 months ago PHP You might have already used any package to download data i...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK