In this script you will get information like AZ, instance ID, IP, keyname, etc…

Please find the script below. Create a file with name getawsinstance.sh. Copy and paste the below content.
nano getawsinstances.sh

!/bin/bash

echo “Grabbing instances in all regions, please wait..”
for region in aws ec2 describe-regions --output text | cut -f4;
do
echo “Listing Instances in region:’$region’…”
aws ec2 describe-instances –region $region \
–output table \
–query “Reservations[].Instances[].{
InstanceId:InstanceId,
Type:InstanceType,
AZ:Placement.AvailabilityZone,
KeyName:KeyName,
Name:Tags[?Key==`Name`]|[0].Value,
Project:Tags[?Key==`project`]|[0].Value,
IP:PublicIpAddress,
State:State.Name,
CPUcores:CpuOptions.CoreCount,
CPUThreads:CpuOptions.ThreadsPerCore
}”
done

Now create a IAM user. After creating you will get the credentials. Download them.

Next run aws configure and give the credentials.

Now execute the script.

./getawsinstances.sh

You will get the output which is in the screenshot.

Leave a Reply