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

前端 未结 17 1224
囚心锁ツ
囚心锁ツ 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:06

    I don't think you can currently do this in the AWS GUI. But here is a way to list all your instances across all regions with the AWS CLI:

    for region in `aws ec2 describe-regions --region us-east-1 --output text | cut -f4`
    do
         echo -e "\nListing Instances in region:'$region'..."
         aws ec2 describe-instances --region $region
    done
    

    Taken from here (If you want to see full discussion)

    Also, if you're getting a

    You must specify a region. You can also configure your region by running "aws configure"

    You can do so with aws configure set region us-east-1, thanks @Sabuncu for the comment.

    Update

    Now (in 2019) the cut command should be applied on the 4th field: cut -f4

    0 讨论(0)
  • 2021-01-29 23:09
    1. First go to AWS Management console and click on Resource group:

    2. Then find Network and Content Delivery and click on the VPC:

    3. Then find Running instances and expand see all regions. Here you can find all the running instances of all region:

    0 讨论(0)
  • 2021-01-29 23:09

    A quick bash oneliner command to print all the instance IDs in all regions:

    $ aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text |xargs -I {} aws ec2 describe-instances --query Reservations[*].Instances[*].[InstanceId] --output text --region {}
    
    # Example output
    i-012344b918d75abcd
    i-0156780dad25fefgh
    i-0490122cfee84ijkl
    ...
    
    0 讨论(0)
  • 2021-01-29 23:10

    @imTachu solution works well. To do this via the AWS console...

    • AWS console
    • Services
    • Networking & Content Delivery
    • VPC
    • Look for a block named "Running Instances", this will show you the current region
    • Click the "See all regions" link underneath
    0 讨论(0)
  • 2021-01-29 23:10

    Every time you create a resource, tag it with a name and now you can use Resource Groups to find all types of resources with a name tag across all regions.

    0 讨论(0)
  • 2021-01-29 23:13

    You may use cli tool designed for enumerating cloud resources (cross-region and cross-accounts scan) - https://github.com/scopely-devops/skew

    After short configuration you may use the following code for list all instances in all US AWS regions (assuming 123456789012 is your AWS account number).

    from skew import scan
    
    arn = scan('arn:aws:ec2:us-*:123456789012:instance/*')
    for resource in arn:
        print(resource.data)
    
    0 讨论(0)
提交回复
热议问题