gpt4 book ai didi

amazon-web-services - Boto3:获取我拥有的EC2图像

转载 作者:行者123 更新时间:2023-12-04 23:40:05 24 4
gpt4 key购买 nike

我想获取我所有的所有ami图像。我尝试了以下内容:

ec2 = boto3.resource('ec2')
owner_id = 'owner_id'
filters = [{'Name': 'owner-id', 'Values': [owner_id]}]
images = ec2.images.filter(Filters=filters).all()

但是我需要在代码中放入owner_id显式。从AWS凭证自动执行此操作有什么解决方案?

最佳答案

您应该可以对所有者使用self。这就是我用的。

boto3conn = boto3.resource("ec2", region_name="us-west-2")
images = boto3conn.images.filter(Owners=['self'])

关于amazon-web-services - Boto3:获取我拥有的EC2图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40213023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com