Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get List of EC2 instances from All regions
# install aws cli first
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --query "Reservations[*].Instances[*].{IP:PublicIpAddress,ID:InstanceId,Type:InstanceType,State:State.Name,Name:Tags[0].Value}" --output=table --region $region
done
@ojotoxy

This comment has been minimized.

Copy link

commented Jan 22, 2018

it works!

@dgacias

This comment has been minimized.

Copy link

commented Feb 9, 2018

It works as expected, but i had to execute first "aws configure" with empty values on everything except the region, because if you do not have any default region, the CLI complaints it does not know in which region work even when executing "aws ec2 describe-regions" alone.
I also tried to pass as argument --region eu-west-1 but it does not work, you have to do the aws configure thing first to stablish a default region.

@eguven

This comment has been minimized.

Copy link

commented Aug 13, 2018

@dgacias just export values before the loop

export AWS_PROFILE=<YOUR-PROFILE>
export AWS_DEFAULT_REGION=<SOME-REGION>
@royharoush

This comment has been minimized.

Copy link

commented Dec 9, 2018

you're d man !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.