Skip to content

Instantly share code, notes, and snippets.

@kshailen
Forked from fboaventura/get_ec2_instances.sh
Created April 17, 2020 01:10
Show Gist options
  • Save kshailen/430047859409ae92b6f9680cf1569e5b to your computer and use it in GitHub Desktop.
Save kshailen/430047859409ae92b6f9680cf1569e5b 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