NoviceMe
NoviceMe

Reputation: 3256

How to filter not equal to in AWS CLI

I am trying to find all non-window images:

aws ec2 describe-images --region us-east-2 --image-ids ami-** --filters "Name=platform, Values=windows"

Above gives me all windows platform id's. Is there a way to do not inside this cli? I tried Values!=, <>. Search through stackoverflow but did not find anything.

Upvotes: 3

Views: 13496

Answers (2)

jmp
jmp

Reputation: 2375

You could use a query on the cli command like this

aws ec2 describe-images --image-ids ami-** --region us-east-2 --query 'Images[?Platform != `windows`]'

Upvotes: 2

John Rotenstein
John Rotenstein

Reputation: 269500

This Python3 code will list all of your own account's AMIs that are not Windows:

import boto3

ec2_client = boto3.client('ec2', region_name='us-east-2')

images = ec2_client.describe_images(Owners=['self'])

for image in images['Images']:
    if 'Platform' not in image:
        print(image['ImageId'])

Upvotes: 2

Related Questions