python - 如何根据状态从 AWS 控制台查询图像 AMI:使用 Python boto3 可用?
问题描述
我需要根据状态从 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 是否有任何确切的关键字,请纠正我
解决方案
关于 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']
推荐阅读
- excel - 用于将完成的行移动到另一个工作表的 VBA 代码会导致奇怪的行为
- reactjs - ReactBootstrap 无法使用 React 子项正确呈现选项卡
- python - Python 上的相关性
- android - 如何从 Activity 获取 SharedPreference 值到 BroadcastReceiver?
- python - 如何计算 Pandas 列中的特殊字符?
- excel - 在不引用工作表名称的情况下从不同工作表中查找单元格的总和
- html - 在其他元素下方对齐 div 并垂直对齐其文本
- html - Remove default spacing/padding on HTML table for email signature in Gmail iPhone app
- django - Django - How to redirect the user after the first login only
- javascript - node js self this call method