Skip to content

Instantly share code, notes, and snippets.

@amcginlay
Last active July 26, 2023 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amcginlay/ed98402295d93f4031d63b7d69c64c62 to your computer and use it in GitHub Desktop.
Save amcginlay/ed98402295d93f4031d63b7d69c64c62 to your computer and use it in GitHub Desktop.
Script will list all running EC2 instances in the current AWS account
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