How to see all running Amazon EC2 instances across all regions?

前端 未结 17 1223
囚心锁ツ
囚心锁ツ 2021-01-29 23:03

I switch instances between different regions frequently and sometimes I forget to turn off my running instance from a different region. I couldn\'t find any way to see all the r

17条回答
  •  囚心锁ツ
    2021-01-29 23:22

    To run jobs in parallel and use multiple profiles use this script.

    #!/bin/bash
    for i in profile1 profile2
    do
        OWNER_ID=`aws iam get-user --profile $i --output text | awk -F ':' '{print $5}'`
        tput setaf 2;echo "Profile : $i";tput sgr0
        tput setaf 2;echo "OwnerID : $OWNER_ID";tput sgr0
        for region in `aws --profile $i ec2  describe-regions --output text | cut -f4`
        do
            tput setaf 1;echo  "Listing Instances in region $region";tput sgr0
            aws ec2 describe-instances --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value , InstanceId]' --profile $i --region $region --output text
        done &
    done
    wait
    

    Screenshot:

提交回复
热议问题