英文:
How to list down all the AMI image IDs for Red Hat in AWS using boto3?
问题
I need the text to be translated into Chinese. Here it is:
我正在处理一个任务,需要验证用户是否使用Cloudtrail日志创建了一个EC2实例,并使用RHEL最新镜像。
我能够使用boto3找到用户使用的AMI镜像ID。
我想检查用户使用的AMI镜像ID是否存在于RHEL提供的镜像ID列表中。
我应该如何列出RedHat Inc的所有AMI镜像ID?
我已经查阅了boto3文档describe_images()
在其中有一个参数Owners,但不确定我应该传递什么来获取Redhat的所有镜像ID。
**附注:**发现Redhat所有者ID是-309956199498,我们可以使用ec2.describe_images()进行查询。
英文:
I'm working on a task where I need to validate if a user has created an EC2 instance with RHEL latest image using Cloudtrail logs for that user.
I was able to find the AMI image IDs used by that user using boto3.
I want to check whether the AMI image ID used by the user is present in the list of image IDs provided by RHEL.
How do I list down all the AMI image IDs for RedHat Inc.
I have gone through the boto3 documentation describe_images()
There's a param Owners in it. But not sure what should I pass in there to get all the image IDs for Redhat.
PS: Found that Redhat owner ID is - 309956199498 and we can query with it using ec2.describe_images()
答案1
得分: 2
以下代码列出了指定区域中所有 RHEL-8 AMI 的 ID:
import boto3
ec2 = boto3.resource('ec2', region_name='us-east-1')
filters = [
{'Name': 'owner-id', 'Values': ['309956199498']},
{'Name':'name', 'Values':['RHEL-8*']}
]
images = ec2.images.filter(Filters=filters).all()
for image in images:
print(image.id)
来源:https://access.redhat.com/solutions/15356.
英文:
The following code lists all RHEL-8 AMI IDs in the specified region:
import boto3
ec2 = boto3.resource('ec2', region_name='us-east-1')
filters = [
{'Name': 'owner-id', 'Values': ['309956199498']},
{'Name':'name', 'Values':['RHEL-8*']}
]
images = ec2.images.filter(Filters=filters).all()
for image in images:
print(image.id)
Adapted from the CLI command in https://access.redhat.com/solutions/15356.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论