通过 CLI 列出所有 AWS AMI 名称?

List all AWS AMI names through CLI?

我想编写一个脚本来打印出在特定日期之前(或之后)创建的所有 AMI。但是,我真的很难做到这一点,所以真诚地感谢您的帮助。

我现在没有多少,但这是我目前拥有的:

aws ec2 describe-images > c:\ami_names.txt

关于如何过滤掉特定日期之前创建的 AMI 的任何提示?

下面是一个查询 2016 年 4 月 1 日之后创建的所有图像的示例:

aws ec2 describe-images --query 'Images[?CreationDate>=`2016-04-01`][]'

我相信您应该能够扩展该示例以获得所需的一切。

您可以使用 jq 来过滤响应

获取在特定日期之前创建的 AMI 的命令,

aws ec2 describe-images --owners self --output json | jq '.Images[] | select(.CreationDate<'$GET_AMI') | {ImageId}' | jq --raw-output '.ImageId'))

这只是给出了 AMI-id 的列表。

如果需要 json 格式,请删除 | jq --raw-output '.ImageId'))

如果需要所有属性,请删除 | {ImageId}