Last active
December 15, 2017 16:36
-
-
Save afolarin/326bc4429c7c28d07a703d075189f8de to your computer and use it in GitHub Desktop.
List AWS Instances By Region
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
#DESC: Providing a overview of all the Instances running across the individual regions, something not readily available in AWS web UI :-/ | |
# Install AWS CLI https://aws.amazon.com/cli/ | |
#-------------------------------------------------------------------------------------- | |
# List all aws instances in all regions, parse out response JSON | |
# Props to: https://github.com/aws/aws-cli/issues/1777 | |
#-------------------------------------------------------------------------------------- | |
function aws-ls-ec2-vm | |
{ | |
for region in `aws ec2 describe-regions --output text | cut -f3` | |
do | |
echo -e "\nListing Instances in region:'$region'..." | |
aws ec2 describe-instances --region ${region} | |
done | |
} | |
#-------------------------------------------------------------------------------------- | |
# Fish out key info: [state, name, type, key] etc. version of above with abreviated json parsed by jq | |
# e.g. | |
# Listing Instances in region:'eu-west-1'... | |
# { | |
# "state": "running", | |
# "name": "Foo-Dev", | |
# "type": "t2.micro", | |
# "key": "Bar-Dev" | |
# } | |
#-------------------------------------------------------------------------------------- | |
function aws-ls-ec2-vm-jq | |
{ | |
for region in `aws ec2 describe-regions --output text | cut -f3` | |
do | |
echo -e "\nListing Instances in region:'$region'..." | |
aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})' | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment