Reputation: 811
As part of a script, I am trying to find the image ID's of already made images. When I run this command for instance:
ec2-describe-images --filter "description=$instance_ID" -O $O -W $W
It returns all information on the resulting images.
IMAGE ami-##dc64da ######/i-e45d81c4/141014 ##### available private x86_64 machine
aki-##### ebs paravirtual xen BLOCKDEVICEMAPPING EBS /dev/sda1 snap-##### 8 true standard
BLOCKDEVICEMAPPING EBS /dev/sdb snap-##### 100 false standard BLOCKDEVICEMAPPING EBS /dev/sdf
snap-##### 100 false standard
Is there anyway I can return only the image id ami-##dc64da
?
Upvotes: 0
Views: 3059
Reputation: 21958
It's possible to use, along with the --filter
option, the built-in --query
option to control the output and display only the ImageId
.
$ aws ec2 describe-images --filter "Name=name,Values=$instance_ID" \ [±bench-branch ✓]
--query 'Images[*].[ImageId]' --output text
# ami-xxxxxxx
Note: --output text
permits to get the output as a text.
Upvotes: 1
Reputation: 310
I guess the answer is so late that it may be irrelevant, but anyways you may try the following :
aws ec2 describe-images --filters "Name=name,Values=i-imageid" | grep -i ami | awk '{ print $9 }'
Upvotes: 0