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 https://www.techrunnr.com/how-to-set-up-access-and-secret-key-in-aws-iam/ .
if you don’t know the region code, go through this link https://www.techrunnr.com/aws-region-names-and-corresponding-region-codes/.

aws configure

aws configure

AWS Access Key ID []: VDSVSDKMOOAPWLSS
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.

#1
#2
#3
Questions Answered
Articles Written
Overall Points
Categories: AWS

Prabhin Prabharkaran

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

0 Comments

Leave a Reply

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.