我可以使用boto3编写简单的函数
def check_ami_exists(ami_id, region):
client = boto3.client('ec2', region_name = region)
response = client.describe_images()
for image in response['Images']:
if ami_id == image['ImageId']:
return True
return False
我使用了上述的方法,但花了一点时间来理解。虽然不是 Python 专业人士,但以下是我的操作步骤。希望对有所帮助。
#EC2 Connection
conn = boto.ec2.connect()
image_status = conn.get_all_images(image_ids='ami-XXX')[0]
image_state = image_status.state
print image_state