Bash Script to get the information related to instances of all regions in AWS.

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.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top