Narendra522
Narendra522

Reputation: 167

ec2-describe-images how to list the creation date of ami for all the AMI's created by specific owner

I am using AWS CLI to get the list of AMI's created by specific owner however I want to get the creation date of the AMI along with the size of the AMI

The command I am using is below.

$ ec2-describe-images --filter "is-public=false" \
    --filter "architecture=x86_64" --filter "owner-id=xxxxxxx"

Please guide me.

Upvotes: 2

Views: 6759

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53713

In AWS CLI, Filters needs to be written as Name=string,Values=string,string and you can use the query param to filter only the attributes you target (creation date and size)

For owner you can use it as a filter or --owners option of the CLI

so something like this will work

aws ec2 describe-images --region us-east-1 \
--filter "Name=is-public,Values=false" --filter "Name=architecture, Values=x86_64" --filter "Name=owner,Values=xxxx"\
--query "Images[*].{size:[BlockDeviceMappings[].Ebs.VolumeSize],date:CreationDate}"

or

aws ec2 describe-images --region us-east-1 \
--owners xxxxxxx
--filter "Name=is-public,Values=false --filter "Name=architecture, Values=x86_64"\
--query "Images[*].{size:[BlockDeviceMappings[].Ebs.VolumeSize],date:CreationDate}"

you will get output like

[
    {
        "date": "2015-10-21T14:39:24.000Z",
        "size": [
            [
                50
            ]
        ]
    },
    {
        "date": "2016-05-17T10:39:00.000Z",
        "size": [
            [
                50
            ]
        ]
    }
]

Upvotes: 3

Related Questions