AWS CLI 命令列出最新的 7 个 ami 和那里的快照

AWS CLI Command to list latest 7 ami' s and there snapshot

我需要一个 cli 命令来列出 7 个最新的 ami 和那里的快照。

基于Fetch last modified object from AWS S3 CLI,您应该可以通过以下方式限制结果集:

aws ec2 describe-images --owners self --query 'sort_by(Images, &CreationDate)[-7:].ImageId' --output text

你应该可以用这样的东西列出关联的快照(但我没有测试):

aws ec2 describe-images --owners self --query 'sort_by(Images, &CreationDate)[-7:].[ImageId, BlockDeviceMappings.Ebs.SnapshotId]' --output text

这应该让您了解如何访问结果集中的字段。使用 documentation 来确定所需的字段。