AWS CLI Script to list all the EC2 Servers in all AWS Accounts in all Regions
To list all EC2 servers across all AWS accounts and regions using AWS CLI, you can use the aws command with the ec2 describe-instances option and specify the --profile and --region options for each account and region. Here's an example command that you can use as a starting point: #!/bin/bash # List of AWS accounts and regions accounts=("account1" "account2") regions=("us-east-1" "us-west-2" "eu-west-1") # Loop through the accounts and regions for account in "${accounts[@]}" do for region in "${regions[@]}" do # Set the profile and region export AWS_PROFILE=$account export AWS_DEFAULT_REGION=$region # Get the EC2 instances in the region instances=$(aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --output text) # Print the instances echo "Instances in $account - $region:" echo "$instances" done done In this scrip