我正在尝试使用 python 获取 EC2 中的 EBS 卷列表。
这是我的代码:
import boto3
import objectpath
aws_account = 'company-lab'
region = 'us-east-1'
session = boto3.Session(profile_name=aws_account, region_name=region)
ec2 = session.client("ec2")
instance_list = ec2.describe_instances()
for reservation in instance_list["Reservations"]:
for instance in reservation.get("Instances", []):
tree = objectpath.Tree(instance)
block_devices = set(tree.execute('$..BlockDeviceMappings[\'Ebs\'][\'VolumeId\']'))
block_devices = list(block_devices)
for volume_id in block_devices:
volume = ec2.Volume(volume_id)
当我尝试这样做时,我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "C:\Users\tdun0002\AppData\Local\Programs\Python\Python38-32\lib\site-packages\botocore\client.py", line 573, in __getattr__
raise AttributeError(
AttributeError: 'EC2' object has no attribute 'Volume'
我正在尝试使用boto3 EC2 卷属性。我想获取任何给定 EC2 实例的 EBS 卷及其大小的列表。我怎样才能做到这一点?
小唯快跑啊
相关分类