[英]How to Query Images AMI's from AWS Console based on their status : Available using Python boto3?
我需要根据其状态从AWS Console获取图像AMI的详细信息:可用。
当我尝试时,它卡住了,无法打印任何行。
Python代码1:
conn = boto3.resource('ec2')
image = conn.describe_images()
print(image) # prints nothing
for img in image:
image_count.append(img)
print("img count ->" + str(len(image_count)))
#prints nothing
此图像AMI是否有确切的关键字,请指正我
如果要进行自己的过滤,请将describe_images(Filters...)
更改为describe_images()
。 注意: describe_images()
返回大量数据。 准备等待几分钟。 在我的系统上,us-east-1的图像为89,362张。
import boto3
client = boto3.client('ec2')
image_count = []
response = client.describe_images(Filters=[{'Name': 'state', 'Values': ['available']}])
if 'Images' in response:
for img in response['Images']:
image_count.append(img)
print("img count ->" + str(len(image_count)))
关于AMI的重要一点是要提供每个 AMI。
如果仅希望列出属于您自己帐户的AMI,请使用Owners=self
:
import boto3
ec2_client = boto3.client('ec2')
images = ec2_client.describe_images(Owners=['self'])
available = [i['ImageId'] for i in images['Images'] if i['State'] == 'available']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.