Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何查询图像AMI';根据状态从AWS控制台获取:是否可以使用Python boto3?_Python_Image_Boto3_Amazon Ami - Fatal编程技术网

如何查询图像AMI';根据状态从AWS控制台获取:是否可以使用Python boto3?

如何查询图像AMI';根据状态从AWS控制台获取:是否可以使用Python boto3?,python,image,boto3,amazon-ami,Python,Image,Boto3,Amazon Ami,我需要从AWS控制台根据图像的状态获取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))) #print

我需要从AWS控制台根据图像的状态获取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是否有任何确切的关键字请更正我,如果您想自己进行过滤更改
描述图像(过滤器…
描述图像()
。注意:
descripe\u images()
返回大量数据。准备好等待几分钟。在我的系统上,为us-east-1提供89362图像

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)))

如果您想自己进行过滤,请将
描述图像(过滤器…
更改为
描述图像()
。注意:
descripe\u images()
返回大量数据。准备好等待几分钟。在我的系统上,为us-east-1提供89362图像

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']

关于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']

@约翰·罗滕斯坦,你能提出你的建议吗ideas@Johnrotenstein,你能提出你的想法吗?非常感谢@John Hanley,你的代码运行良好,并带来了所有图像。非常感谢@John Hanley,你的代码运行良好,并带来了所有图像。非常感谢,@John rotenstein,这正是一种很好的工作方式。owners=self,帮助我获得了自己拥有的图像。我需要知道boto3.client('ec2')和boto3.resource('ec2')之间的区别。基本上,
客户端
版本将1:1映射到官方AWS API调用。
resource
版本是
boto
独有的,给人以更多的对象感。
客户端
版本通常需要对JSON进行大量解析,而
资源
具有可直接访问的字段,但查看这些字段并不总是那么容易。非常感谢,@John Rotenstein,这正是一种很好的工作方式。owners=self,帮助我获得了自己拥有的图像。我需要知道boto3.client('ec2')和boto3.resource('ec2')之间的区别。基本上,
客户端
版本将1:1映射到官方AWS API调用。
resource
版本是
boto
独有的,给人以更多的对象感。
客户端
版本通常需要对JSON进行大量解析,而
资源
具有可直接访问的字段,但并不总是易于查看。