简体   繁体   English

使用Boto3 Python库来自AWS所有区域的聚合实例列表

[英]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. 我想通过一次Boto3 python库从AWS的所有区域获取实例。

We have like below in GCP for aggregated instances list: 我们在GCP中提供了以下汇总实例列表:

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. 当前,我正在使用instance.all()方法,但是存在的问题是,我必须为每个区域分别创建ec2resource,这需要花费大量时间来列出每个区域的实例。 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. 无论您创建的是boto3 EC2资源还是EC2 client ,它都是特定于区域的。 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. 在下面的两个参考文献中,都提到boto api对象只能与一个区域关联。

Ref: 参考:

  1. Reference 1 参考1
  2. Reference 2 参考2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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