简体   繁体   中英

Aggregated instance list from all regions of AWS using Boto3 Python library

I want to get instances from all regions of AWS in a single call of Boto3 python library.

We have like below in GCP for aggregated instances list:

request = service.instances().aggregatedList(project=project)

Currently I'm using instance.all() method but problem with this is that, I've to create ec2resource for each region separately which takes lot of time for listing instances from each region. Currently my code is as below:

region='us-east-2'
ec2resource = boto3.resource('ec2', region_name=region, aws_access_key_id=ac_k, aws_secret_access_key=sec_k)    
instances = ec2resource.instances.all()

Is there any alternate and time efficient solution for above problem so that I can get all instances from all regions in a single call and save time?

Whether you create boto3 EC2 resource or EC2 client , it will be region specific. So there is no way other than querying each region separately.

In both the ref below, it is mentioned that the boto api object can only be associated with one region.

Ref:

  1. Reference 1
  2. Reference 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM