Last active
July 26, 2023 14:05
-
-
Save amcginlay/ed98402295d93f4031d63b7d69c64c62 to your computer and use it in GitHub Desktop.
Script will list all running EC2 instances in the current AWS account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo '"region","instance-id","instance-type","tags-name","tags-auto-owner"' | |
for region in $(aws ec2 describe-regions --query 'Regions[*].[RegionName]' --output text); do | |
aws ec2 describe-instances \ | |
--region ${region} \ | |
--filters "Name=instance-state-name,Values=running" \ | |
--output json | \ | |
jq --arg region $region -r \ | |
'.Reservations[].Instances[] | [$region, .InstanceId, .InstanceType, (.Tags[] | select(.Key=="Name") | .Value), (.Tags[] | select(.Key=="auto:owner") | .Value)] | @csv' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment