how to extract ec2 instances details to CSV file2 min read

Prabhin Prabharkaran Administrator
DevOps Engineer

He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!

follow me

Hi All, this document deals with how to extract ec2 instances details to CSV file.
There is a certain case you need to get the ec2 instances to detail to some reporting purposes. Right now AWS doesn’t have any option of reporting facility in their web interface but aws CLI does have this option. So here We will show extract instances details using aws cli.

Step 1: Install the aws CLI.

For Ubuntu

apt install python3-pip
pip3 install --upgrade awscli

For Centos

yum install python3-pip
pip3 install --upgrade awscli

Step 2: Configure aws cli, for this execute the below command and enter the following details,

Aws access key
AWS secret key
region name

if you don’t have these key please go through this link .
if you don’t know the region code, go through this link

aws configure

aws configure

AWS Secret Access Key []: **********************
Default region name []: us-west-2
Default output format [None]:

Step 3: Now execute the below command to extract the instances details of the region which you have mentioned in the step 2.

aws 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] ]' > ec2_instance_details.csv

Step 4: Wait for the above statement to complete. Now you can see a new file has been created named ec2_instance_details.csv. If you open the file, all the details instances are available.


© 2019, Techrunnr. All rights reserved.

Questions Answered
Articles Written
Overall Points

Related posts

Leave a Reply