Skip to content

Instantly share code, notes, and snippets.

@fboaventura
Last active April 17, 2020 01:10
Show Gist options
  • Save fboaventura/e76f2f751604d8a895259899d06b98f8 to your computer and use it in GitHub Desktop.
Save fboaventura/e76f2f751604d8a895259899d06b98f8 to your computer and use it in GitHub Desktop.
List all EC2 instances
#!/usr/bin/env bash
# Prereqs:
# Ubuntu 16.04+: apt install awscli jq
# Centos 7+ : yum install awscli jq
set +m
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do
aws ec2 describe-instances --region "$region" | jq ".Reservations[].Instances[] | {type: .InstanceType, state: .State.Name, tags: .Tags, zone: .Placement.AvailabilityZone}" &
done; wait; set -m
cayenne :: ~/bin » set +m
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do
aws ec2 describe-instances --region "$region" | jq ".Reservations[].Instances[] | {type: .InstanceType, state: .State.Name, tags: .Tags, zone: .Placement.AvailabilityZone}" &
done; wait; set -m
{
"type": "t2.micro",
"state": "pending",
"tags": null,
"zone": "us-east-1e"
}
cayenne :: ~/bin » set +m
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do
aws ec2 describe-instances --region "$region" | jq ".Reservations[].Instances[] | {type: .InstanceType, state: .State.Name, tags: .Tags, zone: .Placement.AvailabilityZone}" &
done; wait; set -m
{
"type": "t2.micro",
"state": "terminated",
"tags": null,
"zone": "us-east-1e"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment